Link to home
Start Free TrialLog in
Avatar of David C
David CFlag for United Kingdom of Great Britain and Northern Ireland

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()

Open in new window

Avatar of Michael
Michael
Flag of Belgium image

What if you add cnn.open();
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David C

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.