如何使用NOT IN datatable.select

编程入门 行业动态 更新时间:2024-10-11 07:34:35
本文介绍了如何使用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

本文发布于:2023-11-11 05:17:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   datatable   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!