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

LVL 1
takwirirarAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
comment out these 2 rows:
        ds.Clear()
        cmd.Dispose()
0
 
MichaelBusiness AnalystCommented:
What if you add cnn.open();
0
 
takwirirarAuthor Commented:
Thanks!
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.