Solved

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

Posted on 2008-10-17
4
286 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

18 Experts available now in Live!

Get 1:1 Help Now