Filter Datatable Error

i have this assign expression:
dt1=(From d In dt
Group d By k=d(“colum1”).toString.Trim Into grp=Group
Where grp.Count =1
Select grp.First()).CopyToDatatable

this return an error “The source contains no DataRows”.
How can i catch / prevent this error?


you can apply this pattern for handling empty filter result:

drDuplicates from this example is of datatype List(Of Datarow)!

Thanks, but it doesn’t work

please tell us what is not working so we can help. Thanks

it is possible to check only if dt1 is empty?

so the problem is not the pattern it is the flow implementation

checking dt1 is Null

  • is not the case so youl would receive a not set to instance exception

checking empty datatable

  • (will not harm the pattern as long there is a columk in the column definition)

otherwise go for debuging, set a breakpoint before the assign statement and inspect dt1 within the locals

Also ensure that variables are correct wired for the different returns

add AsEnumerable to dt
From d In dt.AsEnumerable
Group …