So I encountered an error whenever there’s no data to be copied to datatable. So I change it as below to cater that error but seems like it doesn’t work with those variable type.
I change it to - FilteredRows as System.Collections.Generic.IEnumerable<System.Data.DataRow>:
Linq query:
FilteredRows = (From d In MainDT.AsEnumerable
Group d By k=d("UPDATED_BRN").ToString.Trim Into grp=Group
Let check = grp.Any(Function ( r ) CheckOrderDT.AsEnumerable.Any(Function (x) x("ACCNT_ID").ToString.Trim.Equals(r("ROW_ID").ToString.Trim )))
From g In grp
Let ra = New Object(){g(0),g(1),g(2),g(3),g(4),g(5),g(6),g(7),g(8),g(9), If(check, "Available",g(10))}
Select ResultDT.Rows.Add(ra))
ResultDT = If(FilteredRows.Any, FilteredRows.CopyToDatatable, MainDT.Clone)
Hope anyone can help me on this. Very much appreciated.
set breakpoint and test parts of the LINQ in the watch box / immediate panel
decompose the LINQ by
(FilteredRows = (From d In MainDT.AsEnumerable
Group d By k=d("UPDATED_BRN").ToString.Trim Into grp=Group
Select grp.toList).toList (returns a List(list(of Datarow)
outer list=groups, inner list the group members
process groups and members within a nested for each