我有一个DataTable(Ado.Net)与列'状态。这列包含的值(每个记录)
I have a DataTable (Ado.Net) with column 'Status'. This column holds the values (in each records)
['红','绿','蓝','黄','白','OtherColors']
我要选择所有状态值不红,绿,蓝
I want to select all the rows which status value not Red,Green,Blue
什么样过滤前pression的使用来选择与我所提出的条件的数据。所以,我想才达到的一些东西像我们在SQL查询中使用(WHERE 状态NOT IN('红','绿','兰')的
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')
注:该项目运行.NET 2.0,我不能使用LINQ
NB:This project is running .NET 2.0 i cant use linq
推荐答案我已经测试过它,它的工作原理所需的:
I have tested it, it works as desired:
DataRow[] filtered = tblStatus.Select("Status NOT IN ('Red','Green','Blue')");由此产生的的DataRow [] 只包含 OtherColors 数据行黄和白色。
如果你可以使用LINQ我会preFER是:
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")));更多推荐
如何使用NOT IN datatable.select
发布评论