Solved

Help with populating ComboBox

Posted on 2013-11-15
4
260 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 70

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
Footer for each row on Gridview 2 33
VB.NET 2008 - SQL Timeout 9 34
Iteration Help (Asp.net VB) 5 24
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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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