I have four columns in my table:
Item_name
Brand
Model
Price
I need to show results when I select an Item_name
. When I select another oil, then show those result.
Private Sub ComboBox7_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox7.SelectedIndexChanged
Dim cmd As New SqlCommand
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM Table_14 WHERE Item_Name='" & ComboBox7.Text & "'"
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
If table.Rows.Count() > 0 Then
ComboBox2.Text = table.Rows(0)(1).ToString()
ComboBox3.Text = table.Rows(0)(2).ToString()
TextBox1.Text = table.Rows(0)(3).ToString()
End If
End Sub
After populating your DataTable
, you need to bind it to multiple controls - one for each column. If Item_Name
is the column that you want to select from then that is the column that gets bound to the ComboBox
, while other columns would be bound to a TextBox
or Label
, eg
adapter1.Fill(table1)
itemNameComboBox.DisplayMember = "Item_Name"
itemNameComboBox.DataSource = table1
modelTextBox.DataBindings.Add("Text", table1, "Model")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.