具有多个条件的数据表选择 [英] Datatable select with multiple conditions

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

问题描述

我有一个包含 4 列 A、B、C 和 D 的数据表,因此 A、B 和 C 列的特定值组合在数据表中是唯一的.

I have a datatable with 4 columns A, B, C and D such that a particular combination of values for column A, B and C is unique in the datatable.

目标:对于给定的 A、B 和 C 列值组合,找出 D 列的值.

Objective: To find the value of column D, for a given combination of values for column A, B and C.

我想循环数据行集应该这样做.有没有办法使用 Datatable.Select() 来完成这个?更具体地说 - 我可以在选择过滤器中有多个条件,即逻辑 AND 运算符连接 A、B 和 C 列中的每一列的条件.

I guess looping over the set of data rows should do it. Is there a way to use Datatable.Select() to accomplish this? To be more specific - can I have multiple conditions in the select filter i.e. a logical AND operator connecting conditions for each of the columns A, B and C.

推荐答案

是的,DataTable.Select 方法支持布尔运算符,就像在真正的"SQL 语句中使用它们一样:

Yes, the DataTable.Select method supports boolean operators in the same way that you would use them in a "real" SQL statement:

DataRow[] results = table.Select("A = 'foo' AND B = 'bar' AND C = 'baz'");

请参阅 MSDN 中的 DataColumn.Expression对于 DataTable 的 Select 方法支持的语法.

See DataColumn.Expression in MSDN for the syntax supported by DataTable's Select method.

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

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