PDA

Click to See Complete Forum and Search --> : MS Access and Combo Box


Cagez
Feb 22nd, 2003, 06:11 PM
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! :)

Wallabie
Feb 23rd, 2003, 04:45 AM
Just a quick note....it would help if you posted the code you've got and someone could check where you've gone wrong.

Cagez
Feb 23rd, 2003, 09:08 AM
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?

Iouri
Feb 23rd, 2003, 10:06 AM
Create a dataset from your table and then populate the combo from the required field


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