Newbie Databound combo question - HELP!!! (VB.NET)

  • Thread starter Thread starter Aaron Ackerman
  • Start date Start date
A

Aaron Ackerman

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??
 
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??
|
|
|
 
Hi Aaron,

For you wish, I have translated my code into VB.net:

Try
Dim adapter As SqlDataAdapter = New SqlDataAdapter("select *
from jobs", "server=localhost;database=pubs;uid=sa;pwd=")
Dim ds As DataSet = New DataSet
adapter.Fill(ds)
ComboBox1.DataSource = ds
ComboBox1.DataSource = ds.Tables(0)
ComboBox1.DisplayMember = "job_desc"
ComboBox1.ValueMember = "job_id"

Catch ex As Exception
MsgBox(ex.Message)
End Try

Hope this helps,

Best regards,
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??
|
|
|
 
Back
Top