Hi Aaron,
You can bind the ComboBox like this:
try
{
DataSet ds=new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter("select * from
jobs","server=localhost;database=pubs;uid=sa;pwd=");
adapter.Fill(ds);
comboBox1.DataSource=ds.Tables[0];
comboBox1.DisplayMember="job_desc";
comboBox1.ValueMember="job_id";
}
catch(Exception ex)
{
MessageBox.Show(ex.Message );
}
I use the default database of SqlServer and use the job_desc column as the
display item of comboBox, job_id column as the value item of the comboBox.
Btw: the DisplayMember property of comboBox is case-sensitive in C#, so you
should type the correct case of the column.
Hope this helps,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Aaron Ackerman" <
[email protected]>
| Subject: Newbie Databound combo question - HELP!!! (VB.NET)
| Date: Thu, 9 Oct 2003 19:52:11 -0400
| Lines: 9
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <
[email protected]>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: ric-64-83-27-134-serial-sta.t1.cavtel.net 64.83.27.134
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:111334
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I have tried forever to get this databound combo to load up in my WinForms
| (VB.NET) project but to no avail.
| I have used all of the data bound properties I can muster both at
| design-time and in code at run time.
|
| Could soemone give me some tips and on how to fill it manually in code in
| case I can't get the data bound stuff to work??
|
|
|