Solved

Help with populating ComboBox

Posted on 2013-11-15
4
257 Views
Last Modified: 2013-11-16
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

0
Comment
Question by:takwirirar
4 Comments
 
LVL 6

Expert Comment

by:Michael
ID: 39650940
What if you add cnn.open();
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39650969
comment out these 2 rows:
        ds.Clear()
        cmd.Dispose()
0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 39651055
Thanks!
0
 
LVL 40
ID: 39652990
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now