Remove data table instead of Copy To Datatable

Hi @Uipath Community

this is my query to get duplicate rows

(From d In dtData
Group d By k=d(“Site ID”).toString.Trim Into grp=Group
Where grp.Count >1
Select grp.toList).SelectMany(Function (x) x).CopyToDatatable

But I have to remove those duplicate rows instead of copy to datatable

any one help please

Thanks
Shaik

Getting a datatable without groups with more then 1 group members we can do:

(From d In dtData.asEnumerable
Group d By k=d("Site ID").toString.Trim Into grp=Group
Where grp.Count = 1
Select g = grp.toList).SelectMany(Function (x) x).CopyToDatatable

Also have a look at:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

as it can happen, that the Linq will filter out all rows

when the case is about getting a datatable with distinct rows we can do:

(From d In dtData.AsEnumerable
Group d By k=d("Site ID").toString.Trim Into grp=Group
Select r = grp.First()).CopyToDatatable

and will decide / adapt of which group member is to take (first, last or others)

Hi @shaik.muktharvalli1

Try this linq query

dtData = dtData.AsEnumerable().Where(Function(row)
dtData.AsEnumerable().Count(Function(x) x(“Site ID”).ToString.Trim = row(“Site ID”).ToString.Trim) = 1
).CopyToDataTable()

Thanks!!

dtDataGroup = dtDataGroup.AsEnumerable().Where(Function (row) dtDataGroup.AsEnumerable().Count(Function (r) r("Site ID").ToString.Trim = row("Site ID").ToString.Trim) = 1 ).CopyToDataTable()

Regards,
Arivu