Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Not In datatable.select

I have a DataTable (Ado.Net) with column 'Status'. This column holds the values (in each records)

['Red','Green','Blue','Yellow','White','OtherColors']

I want to select all the rows which status value not Red,Green,Blue

What the kind of filter expression to use to select data with my proposed criteria. So i want to achive some thing like we used in sql query ( WHERE Status NOT IN ('Red','Green','Blue')

NB:This project is running .NET 2.0 i cant use linq

like image 483
Binson Eldhose Avatar asked Oct 14 '14 11:10

Binson Eldhose


1 Answers

I have tested it, it works as desired:

DataRow[] filtered = tblStatus.Select("Status NOT IN ('Red','Green','Blue')");

The resulting DataRow[] contains only DataRows with OtherColors, Yellow and White.

If you could use LINQ i'd prefer that:

string[] excludeStatus = {"Red","Green","Blue"};
var filteredRows = tblStatus.AsEnumerable()
    .Where(row => !excludeStatus.Contains(row.Field<string>("Status")));
like image 89
Tim Schmelter Avatar answered Oct 15 '22 17:10

Tim Schmelter