如何编写代码来搜索DataGridView中的数据

时间:2017-01-07 17:50:02

标签: vb.net datagridview

我使用以下代码将Excel工作表导入DataGridView,现在我如何编写代码来搜索DataGridView中的数据。

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim myconnection As System.Data.OleDb.OleDbConnection
    Dim dataset As System.Data.DataSet
    Dim mycommand As System.Data.OleDb.OleDbDataAdapter
    Dim path As String = "F:\Project Files\Excel sheet\SalesReport1.xlsx"

    myconnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties=Excel 12.0;")
    mycommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Source Data$] ", myconnection)
    dataset = New System.Data.DataSet

    mycommand.Fill(dataset)

    DataGridView1.DataSource = dataset.Tables(0)

    myconnection.Close()

    Catch ex As Exception
        MsgBox(ex.Message.ToString)
End Sub

0 个答案:

没有答案