d_liberati
(d. liberati)
October 22, 2020, 3:23pm
1
Hi,
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?
Thanks
ppr
(Peter)
October 22, 2020, 3:28pm
2
@d_liberati
you can apply this pattern for handling empty filter result:
drDuplicates from this example is of datatype List(Of Datarow)!
d_liberati
(d. liberati)
October 22, 2020, 3:44pm
3
Thanks, but it doesn’t work
ppr
(Peter)
October 22, 2020, 3:47pm
4
@d_liberati
please tell us what is not working so we can help. Thanks
d_liberati
(d. liberati)
October 22, 2020, 3:49pm
5
d_liberati:
dt1
it is possible to check only if dt1 is empty?
ppr
(Peter)
October 22, 2020, 3:52pm
6
@d_liberati
so the problem is not the pattern it is the flow implementation
checking dt1 is Null
isNothing(dt1)
is not the case so youl would receive a not set to instance exception
checking empty datatable
dt.Rows.Count=0
(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 …