-
MS Access and Combo Box
I have a MS Access db with table 'users' and I want to populate the combo box with the user names from the db (field 'user') from the table.
I have a connection, a data adapter and a data set, but whenever I set DataSource and DisplayMember of my combo box, I try it out and nothing appears.
Any idea what the problem can be - or point me in the direction of a tutorial, I've done this purely through VB.net docs and an modified example from these forums.
Thank you! :)
-
Just a quick note....it would help if you posted the code you've got and someone could check where you've gone wrong.
-
I was thinking about that, but I didn't do it through code, I did it through the designer (Toolbox->Data->OleDbConnection/OleDbAdapter/DataSet)... Should I do it the other way?
-
Create a dataset from your table and then populate the combo from the required field
Code:
Dim cnNorthwind As New SqlConnection("Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind")
Dim cmCustomers As New SqlCommand("uspS_Company", cnNorthwind)
Dim daCustomers As New SqlDataAdapter(cmCustomers)
Dim dsCustomers As New DataSet()
Dim drCustomers As DataRow
'fill DataSet
daCustomers.Fill(dsCustomers, "Customers")
'adding items with DataRow from DataSet
For Each drCustomers In dsCustomers.Tables("Customers").Rows
cbo.Items.Add(drCustomers("CompanyName"))
Next