Resolved How to pass a query reault which has every fields data to from?

Socarsky

Well-known member
Joined
Dec 27, 2012
Messages
173
Location
Jakarta/Indonesia
Programming Experience
Beginner
I need to know that how do I pass data to form controls if I get a result of my query to SQL?
I need to pass data to those TextBoxes, Comboboxes and RadioButton after I get a positive result of my query.
Each control related one code and that code contain each controls data in a table.
It is not a gridview mean that I cannot bind whole datarows at the same time.
I need to make it parse and bind it to each controls design on form. Hope I could convey.
clipboard02v.jpg
 
Last edited:
Each control has a DataBindings property that allows you to bind specific properties. If you have a DataTable that you want to display one record at a time from then you can bind like this:
VB.NET:
BindingSource1.DataSource = myDataTable
TextBox1.DataBindings.Add("Text", BindingSource1, "Column1")
ComboBox1.DataBindings.Add("SelectedValue", BindingSource1, "Column2")
'etc
You can then navigate the data by calling MoveNext and MovePrevious in your own code or you can add a BindingNavigator to do it automatically.

The RadioButtons are a slightly different affair. The property of interest for a RadioButton is Checked, which is type Boolean, but most likely you have a group of RadioButtons that correspond to a single column in the database that is text or numeric. That means that you can't really bind your data directly to the RadioButtons. What you can do is to create a UserControl that contains the RadioButtons and add a property of the appropriate type to that UC such that it can be bound to the appropriate column of your DataTable. In the property getter and setter, you can translate between the property value and the Checked properties of the RadioButtons.
 
All controls binding A result of query which type in a text and press on a search button, and if there is a positive result then I must display the records in each controls. What if it does not happen then I need to input a new records with text boxes and Dropbox which also has some constant data to choose. I mean dropboxes are showing constant data for choosing as stock card type. Means they have a binding code in another sub.
 
If you want to bind a ComboBox to a field of a record as you would a TextBox but you also want to bind a list of items to select from then you need to use simple data-binding, as I demonstrated earlier, and complex data-binding as well. Let's say that you have a Parent table with ParentID and ParentName columns and a Child table with ChildID, ParentID and ChildName columns. You would bind the ChildName column to a TextBox and the ParentID column to a ComboBox. You'd want the user to see ParentName values though, so the binding would go like this:
parentBindingSource.DataSource = parentDataTable
childBindingSource.DataSource = childDataTable

'Bind the Parent table to the ComboBox using complex data-binding.
parentComboBox.DisplayMember = "ParentName"
parentComboBox.ValueMember = "ParentID"
parentComboBox.DataSource = parentBindingSource

'Bind the Child table to the TextBox and ComboBox using simple data-binding.
childNameTextBox.DataBindings.Add("Text", childBindingSource, "ChildName")
parentComboBox.DataBindings.Add("SelectedValue", childBindingSource, "ParentID")
 
Thanks a lot for your example they are good enough to catch the idea a way of how to do that
 
If you want to bind a ComboBox to a field of a record as you would a TextBox but you also want to bind a list of items to select from then you need to use simple data-binding, as I demonstrated earlier, and complex data-binding as well. Let's say that you have a Parent table with ParentID and ParentName columns and a Child table with ChildID, ParentID and ChildName columns. You would bind the ChildName column to a TextBox and the ParentID column to a ComboBox. You'd want the user to see ParentName values though, so the binding would go like this
Exactly I have parent and child table just like you mention it. They will be so usefull for me to query DB.
clipboard01js.png
 
Back
Top