Solved

Help with populating ComboBox

Posted on 2013-11-15
4
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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