David C
asked on
Help with populating ComboBox
I have the code below trying to populate a ComboBox but its not working. Any ideas?
Dim cnn As SqlConnection = New SqlConnection("server=;database=;uid=;pwd=;")
Dim cmd As SqlDataAdapter = New SqlDataAdapter("select top 10 [ID],[Name] from dbo.names", cnn)
Dim ds As New DataSet()
cmd.Fill(ds)
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "ID"
ds.Clear()
cmd.Dispose()
What if you add cnn.open();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
The role of a DataSet is to maintain relations between tables. When you have tables that are not linked together or a single table, you do not need a DataSet.
Fill in a DataTable object instead of the DataSet, you will save the overhead of the DataSet that you do not use.
Fill in a DataTable object instead of the DataSet, you will save the overhead of the DataSet that you do not use.