简体   繁体   中英

C# DataTable.Select() - How do I format the filter criteria?

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?

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 .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM