Hi everyone. this doesn't work
DataRow[] mySelectedRows = myDataTable.Select("processed <> True");
myDataTable has a row named processed. I would like to select the rows from this table where processed is not equal to True. Can anyone help?
Hi everyone. this doesn't work
DataRow[] mySelectedRows = myDataTable.Select("processed <> True");
myDataTable has a row named processed. I would like to select the rows from this table where processed is not equal to True. Can anyone help?
You need Where
to filter, and a lambda expression as argument:
DataRow[] mySelectedRows = myDataTable.Where(x => !x.processed).ToArray();
Is processed a bool or a string?
If a bool then "not processed" should work otherwise if its a string "processed <> 'True'" - using single quotes as the delimiters within the where string. It would be worth checking the values in the table/column at the point at which you're querying the data to make sure you're testing against the right thing (this has bitten me in the past).
This should work just fine, but it will not return rows where processed
is null
.
To include nulls, try this:
DataRow[] rows = myDataTable.Select("isnull(processed, false) <> true");
SQL null is an indeterminate value. It does not equal the boolean value true
, but it does not not equal true either. (See Null (SQL).)
For the general filter expression reference, see the DataColumn.Expression
MSDN topic.