How to compare 2 datatable values

Hi - I have 2 datatable with only 1 col and I need to find if Data table 2 has all the values in Data table 1.Uipath

Finding how values in List2 matches from List1.
Thanks

Try this out:

Hi @gsripada

U can try this way

  1. Use Read range to read the first datatable (list1) and store in dt1 variable

  2. Use Read range to read the second datatable (list2) and store in dt2 variable

  3. Use assign activity to write below query which compares two datatables and gives the common rows between them

dt3 = dt2.AsEnumerable().Intersect(dt1.AsEnumerable(),System.Data.DataRowComparer.Default).CopyToDataTable

  1. Now use an if condition like this

dt3.Rows.Count=dt1.Rows.Count

if it is true:

then u can say all the values in datatable 2 are in datatable1

if it false:
then u can say all the values in datatable 2 are not in datatable1

Hope this helps you

Mark it as solution if it resolves ur query

Regards

Nived N

Happy Automation

1 Like

@gsripada

A similar approach less relying on row count compare is following:

Assign Activity
LeftSide: CheckResult (Boolean)
Right side:

dt2.AsEnumerable().Except(dt1.AsEnumerable(),System.Data.DataRowComparer.Default).Count = 0

It does do: check if a dt2 row is found in dt1 and exclude it from the count. Incase of a dt2 rows is not found in dt1 then it counts it. If Final count > 0 then we got rows from dt2 not present in dt2

1 Like

Thanks, will try and let you know.

Thanks, will try and let you know if it works .

Hi ppr,

What if I want to compare only one common column value in two data tables, how do do that?

1 Like