firs of all you should add these libraries in your form
Imports System
Imports System.Data
Imports System.Data.OleDb
Then copy and pase this code hope this would help you.
If ComboBox1.Text = "" Then
MessageBox.Show("Please Select a Search Field From Combobox!", " You Software name ", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf TextBox5.Text = "" Then
MessageBox.Show("Please Enter Search Criteria To Search Record!", "You Software name", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Try
'Set up connection string
Dim cnString As String
cnString = ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\DB.mdb;")
'Create connection
Dim conn As OleDbConnection = New OleDbConnection(cnString)
'Try
' Open connection
conn.Open()
Dim sqlQRY As String = "SELECT * FROM YourTable Name WHERE(" + Me.ComboBox1.SelectedItem + ")LIKE('%" + Me.TextBox1.Text + "%');"
'create data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlQRY, conn)
'create dataset
Dim ds As DataSet = New DataSet
'fill dataset
da.Fill(ds, "YourTableName")
'get data table
Dim dt As DataTable = ds.Tables("YourTable Name")
'display data
Dim row As DataRow
For Each row In dt.Rows
TextBox1.Text = row("C1Name")
TextBox2.Text = row("C2Name")
TextBox3.Text = row("C3Name")
TextBox4.Text = row("C5Name")
Next row
If ds.Tables("YourTableName").Rows.Count = 0 Then
MessageBox.Show("Sorry No Record Found Please Try Again!", " You Software name ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
' Close connection
conn.Close()
Catch ex As OleDbException
MessageBox.Show("Customer Not found" + ex.Message)
End Try
End If
I hope this would help pleae mark thrad solved if it help.
Naveed_786
Posting Whiz in Training
268 posts since Jul 2010
Reputation Points: 20
Solved Threads: 11