c#如何在select语句中指定不是? [英] c# How do I specify a not in a select statement?
问题描述
我在数据集上使用select方法来检索符合我的条件的结果:
I'm using a select method on a dataset to retreive the results that match my condition:
foreach (DataRow dr in dsPone2.Tables["tt-pone"].Select(strWhereCondition))
{
dsPone.Tables["tt-pone"].ImportRow(dr);
}
如何从
strWhereCondition += " AND poneid = 0 and aoneid = 0 and tranid = 0";
到哪里tranid不是0?
To where tranid is NOT 0?
我是否使用<>
或!=
?
推荐答案
正如通常情况一样,咨询文件是前进的道路。 DataTable.Select(string)
重定向到 DataColumn.Expression
来记录过滤器表达式中允许的内容 - 运算符列表显示 <>
而不是!=
。
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 !=
.
个人我会尽量避免基于字符串的过滤,并使用LINQ to DataSet,但当然需要.NET 3.5或更高版本。
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.
这篇关于c#如何在select语句中指定不是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!