You are on page 1of 2

Dim str As String = ("Data Source=.

\INSTANCE;initial
catalog=example;user=sa;password=gariahat")

Dim con As New SqlConnection(str)


If ComboBox1.SelectedIndex = 0 Then
Dim searchtext As String = TextBox1.Text
Dim cmd As New SqlCommand("select * from item where broker_id
like '%" & searchtext & "%'", con)
Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)

MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
ElseIf ComboBox1.SelectedIndex = 1 Then
Dim searchtext As String = TextBox1.Text
Dim cmd As New SqlCommand("select * from item where name like '%"
& searchtext & "%' order by broker_id", con)
Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)

MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
ElseIf ComboBox1.SelectedIndex = 2 Then
Dim searchtext As String = TextBox1.Text
Dim cmd As New SqlCommand("select * from item where lot_no like
'%" & searchtext & "%'order by broker_id", con)
Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)
MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
ElseIf ComboBox1.SelectedIndex = 3 Then
Dim searchtext As String = TextBox1.Text
Dim cmd As New SqlCommand("select * from item where place like
'%" & searchtext & "%' order by broker_id", con)
Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)

MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
ElseIf ComboBox1.SelectedIndex = 4 Then
Dim searchtext As String = TextBox1.Text
Dim cmd As New SqlCommand("select * from item where year like '%"
& searchtext & "%' order by broker_id", con)
Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

If (da.Fill(ds, "item")) Then

ItemDataGridView.DataSource = ds.Tables(0)

MessageBox.Show("match found")

Else

MessageBox.Show("match not found")

End If
End If

End Sub

You might also like