我尝试使用此LINQ代码从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()
但它显示错误
Lambda parameter 'row' hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a query expression.
任何的想法?
是 - 阅读错误消息.您已经row
在方法中调用了一个变量,因此您需要为lambda表达式中的参数选择一个不同的名称.例如:
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()