Skip empty space using LINQ Query

Hello everyone.

I’m using a LINQ Querry to format some cells in a datatable using substring.

This is my code: (From roww In DT.AsEnumerable() Select DT.Clone.Rows.Add(Cstr (roww.Item(0)).Substring(0,4),roww.Item(1),roww.Item(2),roww.Item(3), Cstr (roww.Item(4)).Substring(0,4))).CopyToDataTable

My problem is: In column 4, there are some cells that are empty, so i get an error when i run it. How can I adjust my querry to skip the empty cells?

Using the if activity I would write down: String.IsNullOrWhiteSpace(roww.item(4)). How to put it in a Linq Query?

@luan.quirino1

First remove rows whose Column 4 value is empty and then apply your linq query on it.

Can’t remove the rows because i have data on the other cells.

(From row in DT.AsEnumerable() 
Let v1 = If(isNothing(row(0) OrElse String.IsNullOrEmpty(row(0).toString.Trim),"",row(0).toString.Substring(0,4))
Let v2 = If(isNothing(row(4) OrElse String.IsNullOrEmpty(row(4).toString.Trim),"",row(4).toString.Substring(0,4))
Let ra = new Object(){v1,row(1),row(2),row(3),v2}
Select r= DT.Clone.Rows.Add(ra)).CopyToDataTAble

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