Find the number of data you want in the data table


I Used…
Dt.Select(“[Result] = ‘Fail’”).CopytoDatatable.RowCount

An error occurs if there is no ‘Fail’ data.

How can I find the number by query?


You need not do copytodatatable you can directly use count that way you wont get any error

also another way is dt.AsEnumerable.Where(function(x) x("Result").ToString.Equals("Fail")).Count

or your way Dt.Select("[Result] = 'Fail'").Count


1 Like

@minth08 ,

Could check with the below post as well om handling the error :

1 Like

Filter Data Table on Result = “Fail” into a tempDT

If tempDT.Rows.Count > 0
Then get ConsumerNumber
Else do whatever is necessary if there are no Fails

1 Like

dt.Asenumerable.Where(Function(row) row(“Result”).tostring.ToLower.Equals(“fail”)).count

1 Like

Hi @minth08

Try this:

dt.AsEnumerable().Where(Function(row) row.Field(Of String)("Result") = "Fail").Count()

I/P :

Hope it helps!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.