excel导入后过滤Datagridview

时间:2014-07-07 12:52:22

标签: vb.net datagridview

我正在使用此代码将Excel工作表导入datagridview

Dim dt As DataTable = New DataTable
dt.Columns.Add(New DataColumn("PartNumber"))
bs = New BindingSource
bs.DataSource = dt
DataGridView1.DataSource = bs
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ExcelWork.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES""")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", Con)
MyCommand.TableMappings.Add("Table", "Net-informations.com")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
Con.Close()

现在我如何使用文本框????

过滤它

1 个答案:

答案 0 :(得分:0)

您可以使用 DataView

Rowfilter 属性
Dim dv As New System.Data.DataView()
dv.Table = YourDataTable
dv.RowFilter = "Field like '%Parameter%'" 'Or "Field > 12"
Me.DataGridView1.DataSource = dv

Rowfilter 你喜欢SQL查询的 Where 语句

以下是一些例子 Filter DataGridView with the text entered in TextBox
Filtering a Dataset Using Dataview