简体   繁体   English

Linq 查询数据表中的字段计数

[英]Linq query to count field in datatable

I have a datatable that contains a column as "Column-A".我有一个包含“Column-A”列的数据表。 Now if that column contains a value of "Y" or "N", i need to set the count variable.现在,如果该列包含“Y”或“N”的值,我需要设置计数变量。

for that i need to check that if count is greater that 0 or not.为此,我需要检查计数是否大于 0。 How the same can be achieved with the help of LINQ?如何在 LINQ 的帮助下实现同样的效果?

Please guide!请指导!

Try this, it will count the number of rows that contain "Y" or "N" within Column-A :试试这个,它将计算Column-A中包含“Y”或“N”的行数:

int count = dataTable.AsEnumerable()
               .Count(row => row.Field<string>("Column-A") == "Y"
                          || row.Field<string>("Column-A") == "N");

I think this is what you're trying to do?我想这就是你想要做的? If I misunderstood your question, please let me know.如果我误解了你的问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM