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);
}
How do I change the strWhereCondition from
strWhereCondition += " AND poneid = 0 and aoneid = 0 and tranid = 0";
To where tranid is NOT 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 !=
.
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.
you have to use the SQL notation <>
in your case tranid <> 0
Use 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 . 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 also lists a <>
comparison operator. So, that should mean you can do either tranid <> 0
or NOT (tranid = 0)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.