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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With