tags:

views:

1765

answers:

3

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?

+1  A: 

You need Where to filter, and a lambda expression as argument:

DataRow[] mySelectedRows = myDataTable.Where(x => !x.processed).ToArray();
Stefan Steinegger
Doesn't exist on a datatable
Murph
oh, sorry. You could take the records, how is this property called again? By the way: you don't expect that this call results in a call to the database? I assume that the data is already in memory.
Stefan Steinegger
+1  A: 

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).

Murph
You're the man Murph
jim
For reference, which of the two possibilies was the right one?
Murph
sorry for the HUGE delay in my response Murph. It was a string so processed <> 'True' did the trick.
jim
Thanks for letting us know!
Murph
+1  A: 

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.

Jeff Sternal