Solved

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

Posted on 2008-10-17
4
294 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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