Hey group think, me again! In my automation I am trying to compare DT2 to DT1 and return any row that is different from DT1. Row count and columns are static. I just need to make sure no one accidently messed with the static information. Is there a way to do with UiPath activities or will this need to be an invoke code (in which case, what would that be)?
Give a try on:
Using assign activity:
dt2.AsEnumerable.Except(dt1.AsEnumerable,DataRowComparer.Default).ToList().Count()
will return an integer - count of different rows
Otherwise the join datatable activity can be used to identify matching rows on join columns (inner join)
If count of matching rows s is ame as dt1/2 count, then no differences are found
Other options e.g returning the not matching rows is possible with default uipath activities
Question… for the assign would it be: (some int32 variable) = dt2.AsEnumerable.Except(dt1.AsEnumerable,DataRowComparer.Default).ToList().Count()?
Yes, give a try as it is a quick approach
Except is looking on dt2 rows that are not present in dt1 and in this statement will return the count of this evaluation.
@jamills
Yes this is possible
dt2.AsEnumerable.Except(dt1.AsEnumerable,DataRowComparer.Default).ToList() will return a List(Of Datarow) result will be remaining dt2 rows after the except with dt1
if there are rows returned we can use CopyToDataTable and will get a datatable with the structure of dt2
if no rows are returned we would get an exception by using CopyToDataTable
A possible flow could look like this:
Assign Activity:
dt2.AsEnumerable.Except(dt1.AsEnumerable,DataRowComparer.Default).ToList()
to: yourDataRowListVar - Datatype: List(Of Datarow)
If Activity:
Condition: yourDataRowListVar.Count > 0
Then: using an assign activity - dtDiff = yourDataRowListVar.CopyToDataTable
Else: using an assign activity - dtDiff = dt2.Clone