Needed Explanation

Hi
Can anyone explain this expression ?

dtExported.Rows.Cast(Of DataRow)().Where(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”))).CopyToDataTable()

Its a LINQ within Method syntax:

dtExported.Rows.Cast(Of DataRow)()
Similar to dtExported.asEnumerable - makes the datarows available for the LINQ
.Where - filtering
(Function(row) Not row.ItemArray.All(Function(field) field Is DBNull.Value Or field.Equals(“”)
Filter expression: All Column Values from the looped datarow are not blank
)).CopyToDataTable()**
us the datarows passed the filter and copy it to a datatable

Rewritten to Query Syntax:

(From d in dtExported.AsEnumerable
Where d.ItemArray.All(Function (x) Not (isNothing(x) OrElse String.IsNullOrEmpty(x.toString)))
Select r = d).CopyToDataTable

3 Likes

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