数据视图筛选 vb.net

Dataview filtering vb.net

想知道我是否正确地使用数据视图执行此过滤器,它一直向我抛出此错误

Additional information: Filter expression '80' does not evaluate to a Boolean term.

但这是代码

Dim table = DataSet1.Tables("network")
        table.DefaultView.RowFilter = TextBox1.Text
        DataGridView1.DataSource = table

要在 DataVIew 上过滤某些内容,您需要指定应用过滤器的列、比较运算符以及要用于过滤的值。看来你只给了值“80”。

例如,假设感兴趣的列名为 "NumberOfPieces" 并且您在文本框中键入了 80

Dim table = DataSet1.Tables("network")
table.DefaultView.RowFilter = "NumberOfPieces = " & TextBox1.Text
DataGridView1.DataSource = table

这将使用列 "NumberOfPieces" 中值(数值)等于 80 的所有行过滤视图。您可以使用其他运算符,例如 Greater/Lesser Than ( >= <= ) 或更复杂的结构,这些结构在 MSDN 页面中详细介绍了 Expression property of the DataColumn object