Except Function

DT 1:
73152
81259
83494
349641
139954
166158
257758
257762

DT2:
349641
139954
166158
257758
257762

DT1.AsEnumerable().Except(DT2.AsEnumerable(),System.Data.DatarowComparer.Default).CopyToDatatable

It does not work, the func returns all DT1 why?

Hi,

you’re trying to use LINQ to find the rows in DT1 that are not present in DT2. The issue might be related to the comparison of DataRow objects.

you can use below query

DT1.AsEnumerable().Except(DT2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable

there are a few possible reasons

  • missmatching datacolumn datatypes
  • untrimmed values

You can analyse mor in details or give a try with an alternate like

(From d in dt1.AsEnumerable
Let c1 = d(0).toString.Trim
Let chk = dt2.AsEnumerable.Any(Function (d2) d2(0).toString.Trim.Equals(c1))
Where not chk
Select r = d).CopyToDataTable

feel free to adapt the 0 to the column name and if needed add more check cols into the match part

Handling empty results:
:ambulance: :sos: [FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum

Thanks!! its work now

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