Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq query to count field in datatable

I have a datatable that contains a column as "Column-A". Now if that column contains a value of "Y" or "N", i need to set the count variable.

for that i need to check that if count is greater that 0 or not. How the same can be achieved with the help of LINQ?

Please guide!

like image 216
xorpower Avatar asked Aug 10 '11 14:08

xorpower


1 Answers

Try this, it will count the number of rows that contain "Y" or "N" within Column-A:

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.

like image 159
Donut Avatar answered Sep 18 '22 01:09

Donut