error when tried to delete empty rows from datatable

I tried this LINQ code to delete empty rows from datatable

 NewDt = NewDt.Rows.Cast(Of DataRow)().
                Where(Function(row) Not row.ItemArray.All(Function(field) TypeOf field Is System.DBNull OrElse String.Compare(TryCast(field, String).Trim(), String.Empty) = 0)).CopyToDataTable()

But it showing error

Lambda parameter 'row' hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a query expression.

Any idea?

Jon Skeet
people
quotationmark

Yes - read the error message. You've already got a variable called row in your method, so you need to choose a different name for the parameter in the lambda expression. For example:

NewDt = NewDt.Rows.Cast(Of DataRow)().
              Where(Function(x) Not x.ItemArray.All(
                  Function(field) TypeOf field Is System.DBNull _
                      OrElse TryCast(field, String).Trim() = "").
              CopyToDataTable()

people

See more on this question at Stackoverflow