?
Solved

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

Posted on 2008-10-17
4
Medium Priority
?
302 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 2000 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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