How to bind a combox to a database??

George

Member
Joined
Jun 2, 2005
Messages
11
Programming Experience
Beginner
Hi there,

I need to bind a dropdown comboBox to a database and can't for the life of me work out how to go about it.

Could anyone please help me with some pointers?

Many thanks
George
 
Look in the help at the DataSource, DisplayMember and ValueMember properties. Also, a general search for "data binding" would probably yield some valuable reading material if you are new to the subject of data binding.
 
If you add a DB connection, DB Adapter and Dataset you can use the following.
Public Sub LoadComboBox1()
SqlDataAdapter1.Fill(DataSet1)
With ComboBox1
.DisplayMember = "Field Name"
.ValueMember = "Unique Identifier"
.DataSource = DataSet1.Tables("TableName")
End With
End Sub

Does anyone happen to know how to display 2 DB Fields in a combobox? I'm looking to display a application name and a version, held in diffrent fields.
 
Thanks for the reply Francis that really helped. I wonder if I could impose further on you ?
What I need to do now is to display the relevent deatils in my 5 textboxes.

When i click on the combobox drop down list and select customerID1,the first name, last name, city, state and zip code need to appear in my 5 readonly text boxes...If I select customerID 4 then those particular details need to apperar...etc...etc

Hope you can help with this, it might just stop me from pulling every last hair out of my head.

Thanks again
George
 
Mongoose said:
Does anyone happen to know how to display 2 DB Fields in a combobox? I'm looking to display a application name and a version, held in diffrent fields.
The only simple way to achieve this would be to add an extra column to your DataTable that is the two columns you are interested in concatenated. It's simple to achieve this using your SQL query. It is not possible to display two seperate columns in a ComboBox via data binding. You could create your own inherited ComboBox that provided the functionality though, if you're keen.
 
I'm not 100% on this one, but I would set a recordset using the customerID, something like:
'CODE'

DIM RS as new adodb.recordset
RS = SQLConnection.Execute ("SELECT * FROM dbTable WHERE customerID='" & Combobox1.SelectedText & "'")
TextBox1.Text = RS.Fields("First Name").Value
TextBox2.Text = RS.Fields("Last Name").Value

'END CODE'

Hope this helps!
 
Thank you, jmcilhinney, never even thought of concatinating the fields, works great!... Maybe next week I'll try to inherent my own Combobox...
 
Back
Top