[英]c# How do I specify a not in a select statement?
I'm using a select method on a dataset to retreive the results that match my condition: 我在数据集上使用select方法检索与我的条件匹配的结果:
foreach (DataRow dr in dsPone2.Tables["tt-pone"].Select(strWhereCondition))
{
dsPone.Tables["tt-pone"].ImportRow(dr);
}
How do I change the strWhereCondition from 我如何从更改strWhereCondition
strWhereCondition += " AND poneid = 0 and aoneid = 0 and tranid = 0";
To where tranid is NOT 0? tranid不是0的地方?
Do I use <>
or !=
? 我是否使用
<>
或!=
?
As is so often the case, consulting the documentation is the way forward. 通常,查阅文档是前进的道路。
DataTable.Select(string)
redirects to DataColumn.Expression
to document what's allowed in a filter expression - and the "Operators" list shows <>
but not !=
. DataTable.Select(string)
重定向到DataColumn.Expression
以记录过滤器表达式中允许的内容-并且“运算符”列表显示<>
但不显示!=
。
Personally I would try to avoid string-based filtering and use LINQ to DataSet instead, but of course that requires .NET 3.5 or higher. 我个人将尝试避免基于字符串的筛选,而改用LINQ to DataSet,但是当然需要.NET 3.5或更高版本。
you have to use the SQL notation <>
您必须使用SQL表示法
<>
in your case tranid <> 0
在您的情况下
tranid <> 0
Use tranid <> 0
. 使用
tranid <> 0
。
The syntax for the expressions is described here . 表达式的语法在此处描述 。
The documentation for the DataColumn.Expression
property details the syntax used by the filterExpression
parameter of the DataTable.Select
method . DataColumn.Expression
属性的文档详细介绍了DataTable.Select
方法的filterExpression
参数使用的语法。 In the Operators section about a third of the way down the page it says... 在“运营商”部分中,页面下方约有三分之一...
Concatenation is allowed using Boolean AND, OR, and NOT operators.
可以使用布尔AND,OR和NOT运算符进行串联。
...and also lists a <>
comparison operator. ...并还列出了
<>
比较运算符。 So, that should mean you can do either tranid <> 0
or NOT (tranid = 0)
. 因此,这意味着您可以执行
tranid <> 0
或NOT (tranid = 0)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.