How can I filter empty rows from datatable without using a loop?

I have a scenario where a datatable can contain a large number of rows. As a result, I cannot repeat and update data using a loop.

I tried the following code,

from row in table.AsEnumerable() where table.Columns.Any(col => !row.IsNull(col)) select row; 

But I can not find a definition for Any () . Is there any namespace I should use to get Any ()?

Any body, please tell me how to fix this or suggest any alternative solutions.

+4
source share
4 answers

In addition to using the System.Linq namespace, you also need to know its types. DataTable.Columns not a common collection (it implements only IEnumerable not IEnumerable<T> ), and the compiler cannot infer a type. You need to do something like this:

 from row in table.AsEnumerable() where table.Columns.Cast<DataColumn>.Any(col => !row.IsNull(col)) select row; 
+7
source

The Any() method is in the System.Linq namespace. The method lives in the Queryable class.

-1
source

use the system.linq namespace if the wireframe version is greater than 2

-1
source

you should include the following:

 using System.Linq; 
-1
source

All Articles