C# .NET BindingSource 过滤器语法参考
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1389831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.NET BindingSource Filter syntax reference
提问by clamp
You can use the Filter property of a BindingSource to do SQL like filtering. For example:
您可以使用 BindingSource 的 Filter 属性来执行 SQL 之类的过滤。例如:
bindingSource.Filter= "Activated = 1"
Is there something like documentation on the exact syntax of this?
是否有关于此确切语法的文档?
I would like to check if a field is not DBNull, so i tried "Field != NULL" but it gives a syntax error.
我想检查一个字段是否不是 DBNull,所以我尝试了“Field != NULL”,但它给出了一个语法错误。
采纳答案by Charles Bretana
The syntax is generally the same as what would you would use in a SQL Where clause, without the "Where", so in this case, it would be
语法通常与您在 SQL Where 子句中使用的语法相同,没有“Where”,因此在这种情况下,它将是
bindingSource.Filter = "Field <> NULL";
If you look at msdn docs for BindingSource.Filter you will see this:
如果您查看 BindingSource.Filter 的 msdn 文档,您将看到:
"To form a filter value, specify the name of a column followed by an operator and a value to filter on. The accepted filter syntax depends on the underlying data source. If the underlying data source is a DataSet, DataTable, or DataView, you can specify Boolean expressions using the syntax documented for the DataColumn..::.Expressionproperty."
“要形成过滤器值,请指定列名,后跟运算符和要过滤的值。接受的过滤器语法取决于基础数据源。如果基础数据源是 DataSet、DataTable 或 DataView,则您可以使用为DataColumn..::.Expression属性记录的语法指定布尔表达式。”
Follow that link to see all the detailed rules
按照该链接查看所有详细规则
回答by tanascius
Have a look at this msdn article. The described syntax should be valid for your BindingSource
, too.
看看这篇 msdn 文章。所描述的语法也应该对您的 有效BindingSource
。
回答by gillonba
What worked for me was
对我有用的是
bindingSource.Filter = "columnName Is Null";
or conversely
或者相反
bindingSource.Filter = "columnName Is Not Null";