Combo boxes

I need to auto populate a combo box from a database.  For example, assuming I have a DB that has a table called Client, and client table is in MS Access like:

ClientID    ClientName    ClientPhone
100002    Best Buy         981-0006
239292    Hooters          393-8434
938423    Powersource   434-4312

then when I populate the combobox called client, I need to have:

     <clientID="100002">Best Buy

does that make sense?  How do I populate that?  Thanks.

LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

try the following code i hope this will help u

            OleDbDataReader dr;
            string sQry="Select ClientId,ClientName from Client";
            OleDbCommand cmd=new SqlCommand (sQry,conn);
            DropDownList1.DataBind () ;
I would make a dataset with a table inside, then fill in the data with a data adapter (with only select command probably) and then set the DataSource, DataMember, DataValueField and DataText field properties. The data adapter and dataset can be made directly from within the IDE and are easy to configure and work with.
ofcourse u can use dataadapter also and it is better to use it instead of datareader
so u can use as follows
actually the main point is populating combo , so u can use anything u want

SqlDataAdapter da=new SqlDataAdapter(sQry,Global.conn );  
DataSet ds=new DataSet();
da.Fill (ds);
DropDownList1.DataBind () ;
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

oops! the abv code is mine , i mean for my app. so just replace it with ur conditions like

string sQry="Select ClientId,ClientName from Client";
OleDbDataAdapter da=new OleDbDataAdapter (sQry,conn );  
DataSet ds=new DataSet();
da.Fill (ds);
DropDownList1.DataBind () ;

substandAuthor Commented:
OleDbConnection connection;
OleDbCommand command;
            //initialize dr dropdown
            using(connection = new OleDbConnection(dbConnectionString))
                  using(command = connection.CreateCommand())
                        string DoctorQuery="Select StaffID, LastName from Staff where NurseOrDoctor=1 order by LastName";
                        command.CommandText = DoctorQuery;
                        OleDbDataReader dr = command.ExecuteReader();
                        DoctorID.DataBind () ;
      catch( Exception ex)
            MessageBox.Show( ex.Message);
substandAuthor Commented:
I am using windows forms, not web forms if that makes a difference.  what you said didn't work, so I changed to this.  There is also no databind method so I took it out and ran it and it said complex databinding only allows an IList ???

any ideas?
substandAuthor Commented:
Nevermind, I found it myself:

(assuming connection and command are predefined)

string NurseQuery="Select StaffID, LastName from Staff where NurseOrDoctor=0 order by LastName";
DataTable nurseTable=new DataTable();
command.CommandText = NurseQuery;
OleDbDataAdapter da2=new OleDbDataAdapter(command);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.