Solved

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

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

821 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