try this following code :
Dim con As New OleDb.OleDbConnection
Dim cmdOle As New OleDb.OleDbCommand
Dim dsOle As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim dtOle As New DataTable
Dim sql As String
Private Sub LoadData()
con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\Only Me\Authors.mdb")
Try
cmdOle = con.CreateCommand
cmdOle.CommandText = "SELECT * FROM Authors "
da.SelectCommand = cmdOle
da.Fill(dsOle, "Authors")
dgAuthor.DataSource = dsOle
dgAuthor.DataMember = "Authors"
dgAuthor.ReadOnly = True
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !!")
End Try
End Sub
Private Sub Search_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData ' Call Load Data Procedure in form load to fill datagrid
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\Only Me\Authors.mdb")
Try
dsOle.Clear()
dtOle.Clear()
cmdOle = con.CreateCommand
cmdOle.CommandText = "SELECT * FROM Authors where YearBorn LIKE '%" & Trim(txtSearchKey.Text) & "%'"
da.SelectCommand = cmdOle
da.Fill(dsOle, "Authors")
dgAuthor.DataSource = dsOle
dgAuthor.DataMember = "Authors"
dgAuthor.ReadOnly = True
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Connection Error !!")
End Try
End Sub Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444