如何使用NOT IN datatable.select [英] How to use Not In datatable.select

查看:1410
本文介绍了如何使用NOT IN datatable.select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆