DataTable的选择与多个条件 [英] Datatable select with multiple conditions

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

问题描述

我有4列A,B,C和D的数据表,使得对A列中值的特定组合,B和C是在DataTable中是独一无二的。

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.

目的::要找到D列的值,值的列A,B和C给定的组合

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'");

请参阅DataColumn.Ex$p$pssion在MSDN 的由DataTable的选择方法支持的语法。

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

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

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