0% found this document useful (0 votes)
26 views2 pages

Dim STR As String

The document defines a method that performs a SQL search on a database table based on the selected index of a combo box. It opens a SQL connection, defines a SQL command string with a LIKE clause to search either the broker_id, name, lot_no, place, or year field based on the combo box selection, executes the command via a data adapter to fill a data set, and sets the results as the data source for a data grid view control while displaying a notification message.

Uploaded by

Arina Rizqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views2 pages

Dim STR As String

The document defines a method that performs a SQL search on a database table based on the selected index of a combo box. It opens a SQL connection, defines a SQL command string with a LIKE clause to search either the broker_id, name, lot_no, place, or year field based on the combo box selection, executes the command via a data adapter to fill a data set, and sets the results as the data source for a data grid view control while displaying a notification message.

Uploaded by

Arina Rizqi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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