Question Combo Box Help

drdisk

New member
Joined
Jan 16, 2011
Messages
1
Programming Experience
5-10
I am trying to get the data to display in a combo box where the Customer ID in the Customers Table and customer ID in the Job Table Match. I am using sql server express 2008 with VB.NET. Below is my code.

ExecuteSQLQuery("SELECT * FROM TBL_Jobs, TBL_Customer WHERE TBL_Jobs.Customer_ID = TBL_Customer.Customer_ID")


If sqlDT.Rows.Count > 0 Then
For i = 0 To sqlDT.Rows.Count - 1
With cboJobs
.Items.Add(sqlDT.Rows(i)("Job_Name"))
(sqlDT.Rows(i)("Job_Name"))
End With
Next
End If

Thanks
Harry
 
For a start, your SQL is outdated. The proper way to join tables is like so:
VB.NET:
SELECT SomeColumns
FROM Parent INNER JOIN Child
ON Parent.ParentID = Child.ParentID
As for displaying data from a DataTable, use data-binding, e.g.
VB.NET:
myComboBox.DisplayMember = "ColumnToDisplay"
myComboBox.ValueMember = "KeyColumn"
myComboBox.DataSource = myDataTable
 
Back
Top