How do i filter empty rows from a datatable without using a loop?
I've scenario where the datatable may contain large number of rows. As a result i am not able to iterate and update the datatable using a loop.
I've tried the following code,
from row in table.AsEnumerable()
where table.Columns.Any(col => !row.IsNull(col))
开发者_如何学Python select row;
But i can't find definition for Any(). Is there any namespace i should use to get Any()?
Any body please tell me how to correct this or suggest any alternate solutions..
Apart from having to use the System.Linq
namespace you also need to make it aware of the element types. DataTable.Columns
is not a generic collection (it implements only IEnumerable
not IEnumerable<T>
) and the compiler cannot infer the 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;
The Any()
method is in the System.Linq
namespace. The Method lives in the Queryable
class
you should include the following:
using System.Linq;
use system.linq
namespace if framework version is greater than 2
精彩评论