Imports System.Data.SqlClient
Imports System.Data
Public Class Form6
Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=example;user=sa;password=gariahat")
Dim da As New SqlDataAdapter
Dim cmd As New SqlCommand
'Dim dr As New SqlDataReader
Dim dt1 As DataTable
Dim ds As New DataSet
Private Sub ItemBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles ItemBindingNavigatorSaveItem.Click
Me.Validate()
Me.ItemBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ExampleDataSet)
End Sub
Private Sub Form6_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ExampleDataSet.item' table. You can move, or remove it, as needed.
'Me.ItemTableAdapter.Fill(Me.ExampleDataSet.item)
End Sub
Private Sub search()
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
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
search()
End Sub
End Class