Compare each line of 2 data tables

Hello everyone!

I was wondering if someone could help me solving a problem.

I have two datatables, with the same column names and have to compare each cell of each row to see if they match

For example:
Col_A Col_B Col_C
1 2 3
4 5 6

Col_A Col_B Col_C
1 2 3
4 7 6

I have to compare if each cell is equal in both datatables and report if there is any mismatch value, in the example that would be Col_B 2nd row (5<>7)

Any suggestion?

it looks like you want to identfy if both datatable are haven the same rows, right?

We can do with

  • LINQ
  • Join DataTable
  • Set Openrations

Approach SetOperations:
getting the rows from dt1 not matching rows in dt2

Assign activity:
Left side: drNonDT1Matchings | datatype List(Of DataRow)
right side:
dtData1.AsEnumerable.Except(dt2.AsEnumerable, DataRowComparer.Default).ToList

getting the rows from dt1 not matching rows in dt2

Assign activity:
Left side: drNonDT2Matchings | datatype List(Of DataRow)
right side:
dtData2.AsEnumerable.Except(dt1.AsEnumerable, DataRowComparer.Default).ToList


Hi @Maria_Carlao ,

It depends how you want to do Reporting, you want it by highliting unmatched values or you want only unmatched cells address or values to be stored somewhere.

This can also be achieved through loop.

1- Read both tables in dt1 and dt2
2- Take foreach row and create it’s index value from property.
First foreach will be on dt1
3 Inside body use assign activity to fetch each cell values like column1 = dt2.row(index)(“column1”).tostring, similarly you have to create 2 more variables to store other column value.

4 use if condition to check if columns = CurrentRow(“column1”)
Then use set color activity or you can also store it’s value in some variable, as I told earlier it depends how you want Reporting?

Let me know if you face any issue.

I always recommend linq first if @ppr solution works better then go with that.



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