加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 过滤DataTable,其中表中不包含List中的项

发布时间:2020-12-16 01:50:05 所属栏目:百科 来源:网络整理
导读:我在查询DataSet.Tables [0]时遇到一些问题,并删除了不符合List的标准的行. //This is my listvar values = new Liststring {"Test","Test2"};// Now I just query the DataSet for anything that doesnt match this listvar query = from x in ds.Tables[0]
我在查询DataSet.Tables [0]时遇到一些问题,并删除了不符合List的标准的行.

//This is my list
var values = new List<string> {"Test","Test2"};

// Now I just query the DataSet for anything that doesnt match this list
var query = from x in ds.Tables[0].AsEnumerable()
            from b in values
            where !x.Field<string>("ColumnName").Contains(b)
            select x;

这工作并返回结果,但它返回2 x组相同的行(我假设因为没有连接).

我怎样才能获得这些行的不同值?

解决方法

听起来你可能想要:

var query = from x in ds.Tables[0].AsEnumerable()
            where !values.Any(b => x.Field<string>("ColumnName").Contains(b))
            select x;

换句话说,查找值中任何值中“ColumnName”字段值不存在的所有行.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读