|
-
Aug 25th, 2003, 12:16 PM
#1
Thread Starter
Lively Member
Fill from dataset
I have a combo box being loaded with the 'id' field from my database. (id is autonumber prim key)
I'm displaying the data in the db with textboxes linked to columns of my db
When i select a diff id from the combobox i want the data in the textboxes to change accordingly.
i think this is the correct sql string, but other than that i dont have a thing
mySQL = "SELECT * FROM Bottle WHERE id = " & cbID.selectedItem
anything at all would be great
thx
db
-
Aug 25th, 2003, 12:48 PM
#2
If you have already filled a dataset with all the customer info then you can just use databinding to link the different textboxes and what not to the dataset and it will change automatically. Just set the datasource properties on the combo and textboxes to the same dataset.
-
Aug 25th, 2003, 01:01 PM
#3
Frenzied Member
Originally posted by Edneeis
Just set the datasource properties on the combo and textboxes to the same dataset.
Not only the same dataset but also using exactly the same objects. If your dataset is myds and the table in it is myTable and you have the fileds 'id' and 'name' in that table then your binding may be like this:
For the textbox:
TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", myDs, "mytable.name"))
and for the combobox:
Combobox1.Datasource=myds
Combobox1.DisplayMember="mytable.ID"
if the objects you are binding not be the same, for example you use
Combobox1.Datasource=myds.mytable
Combobox1.DisplayMember="ID"
the combo still shows the id but changing it wont change the text in the textbox.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 25th, 2003, 03:24 PM
#4
Thread Starter
Lively Member
k, i have about 15 textboxes that must be filled
so for each one do i add the following
TextBoxXX.DataBindings.Add(New System.Windows.Forms.Binding("Text", myDs, "mytable.CorrespondingColumn"))
What do i put the "Text" as?
all the textboxes are already bound to their appropriate columns of the table
-
Aug 25th, 2003, 11:47 PM
#5
Frenzied Member
If you have already bound the text property in designer then that piece of code is automatically genereated, look at the wizard generated code.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 26th, 2003, 08:09 AM
#6
Thread Starter
Lively Member
So I just have to bind the combo box to the id column of the table then??
But when i select a different combobox value, the rest of the fields dont change. How do i bind the combobox so that when i change it's value, the rest of the values also change?
Is this possible, or do i have to do a search of the table and equate the value of the combobox to the id column?
db
-
Aug 26th, 2003, 10:39 AM
#7
Frenzied Member
If you read my previous post carefully, i have answered your question there. When working with designer just set the datasource of your combobox to the dataset, let say myds, and its displaymember property to mytable.ID.
I think you have set the datasource to myds.mytable and displaymember to ID.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|