Imports System.Data.Odbc
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As OdbcConnection = New OdbcConnection()
Dim da As OdbcDataAdapter
Dim ds As DataSet = New DataSet
Dim strcon As String = "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO;Excel 8.0; DBQ=D:\\nicha\\Book1.xls"
conn = New OdbcConnection(strcon)
conn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$]"
da = New OdbcDataAdapter(strSQL, conn)
da.Fill(ds, "Result")
DataGridView1.DataSource = ds.Tables("Result")
End Sub
End Class
Dim strSQL As String
strSQL = "SELECT * FROM [Sheet1$] WHERE [ColumnName] Like @Keyword"
Dim command As OleDbCommand = New OleDbCommand(strSQL, conn)
command.Parameters.AddWithValue("@Keyword", "%" & TextBoxSearch.Text & "%")
da = New OleDbDataAdapter(command)
da.Fill(ds, "Result")
DataGridView1.DataSource = ds.Tables("Result")