Solved

How to create and populate a dropdown with data from the database table?

Posted on 2008-10-17
4
290 Views
Last Modified: 2013-12-17
Hi -

My Windows form needs to have a dropdown displaying values from a table in database.

Here is the sql I need:  strSql = "SELECT CodeNbr, CodeValue FROM Code WHERE (TableName = 'Test') AND (DeleteInd <> 1)"

What control do I use to create a dropdown? And how?

Thanks for your help!
0
Comment
Question by:majathebee
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
ororiole earned 500 total points
ID: 22746588
Go to your toolbox and drag a combobox onto your form.
Click on the combobox where the little triangle is and select "Use databound Items"
Click on the datasource dropdown and a wizard will open, select database.
Select a connection or click new Connection and fill out the server and database you want.
Select Yes save the connection string.
According to your sql your table would be Code? That doesnt look correct. So select the proper table from the list. Click Finish.
Back on the combobox tasks, click Add query.
If you dont know sql, use the query builder and select the fields you want, CodeNbr, CodeValue ? If you know sql enter your query in the box.
Back on the combobox tasks select your display member, either CodeNbr or CodeValue. Whichever one you want to appear in the dropdown.
Then select your value member.
Again on the combobox click Preview Data, then Preview. If you setup your sql right you will see the query return the data. If you didnt then you may have selected the wrong server, database, you dont have access rights, the server isnt running, etc.

Thats about it. Basically the wizard will walk you thru it. If you follow the wizard you will be fine.
0
 

Author Comment

by:majathebee
ID: 22746595
Thank you very much. I'll work on it right now.
0
 

Author Closing Comment

by:majathebee
ID: 31507350
I got it! Thanks for your help. :)
0
 
LVL 16

Expert Comment

by:ororiole
ID: 22746707
Glad I could help. :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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