使用where条件查询数据表 [英] Querying Datatable with where condition

查看:78
本文介绍了使用where条件查询数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的数据表,

I have a datatable with two columns,

Column 1 = "EmpID"
Column 2 = "EmpName"

我想针对列EmpID查询数据表,并 Empname.

I want to query the datatable, against the column EmpID and Empname.

例如,我要获取其中的值

For example, I want to get the values where

(EmpName != 'abc' or EmpName != 'xyz') and (EmpID = 5)

推荐答案

类似这样的事情...

Something like this...

var res = from row in myDTable.AsEnumerable()
where row.Field<int>("EmpID") == 5 &&
(row.Field<string>("EmpName") != "abc" ||
row.Field<string>("EmpName") != "xyz")
select row;

另请参阅 在数据表上 LINQ查询

See also LINQ query on a DataTable

这篇关于使用where条件查询数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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