Hi all,
I'm trying to fill combobox 2 with all items that match the selection in combobox 1. I followed a thread from here, coupled with my limited knowledge, but I got lost in this. any suggestions would be appreciated. I hope this is a simple fix:
ribbons
I'm trying to fill combobox 2 with all items that match the selection in combobox 1. I followed a thread from here, coupled with my limited knowledge, but I got lost in this. any suggestions would be appreciated. I hope this is a simple fix:
Code:
Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim sqlString As String
Dim Connection As New OleDb.OleDbConnection
Connection.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = I:\Siteware\SEED_SYS\SD-Data\seed.mdb;"
sqlString = "SELECT * FROM LabNumber" 'get all records from the Labnumber table
Dim cmd As New OleDb.OleDbCommand(sqlString, Connection)
cmd.Parameters.Add("CompanyName", OleDb.OleDbType.LongVarChar).Value = ComboBox1.Text 'fill ComboBox1 with Company Names
Dim ds As New DataSet 'new dataset
Dim myrow As DataRowView
Dim adap As New OleDb.OleDbDataAdapter(cmd)
adap.Fill(ds, "OldLabNumber") 'fill new data adapter with all labnumbers matching those companynames
If ds.Tables(0).Rows.Count > 0 Then
Dim dv As New DataView
dv.Table = ds.Tables(0)
For Each myrow In dv
ComboBox2.Items.Add(myrow("OldLabnumber").ToString) 'fill ComboBox 2 with all companyname matching the lab numbers
Next
End If
End Sub
End Class
ribbons