How to get difference records of 2 datatable

Hi,

My query is how we get difference records between 2 datatabe.
I’ll already tried linq but that gives me wrong output.

Hi @itbuddy1

Could you share you LinQ Code or the input files then we will provide you the LinQ code.

Hope it helps!!

sure,
I’ll provide you the input files

1 Like

Input1.xlsx (9.1 KB)
Input2.xlsx (8.9 KB)
Required output.xlsx (8.9 KB)

@itbuddy1

Just follow this link:

Hopefully it helps

Hi @itbuddy1

You can try this in invoke code

Dim rowsToRemove As New List(Of DataRow)
For Each x As DataRow In in_dt1.AsEnumerable()
    For Each y As DataRow In in_dt2.AsEnumerable()
        If CInt(y("CASE ID").ToString).Equals(CInt(x("CASE ID").ToString)) Then
           rowsToRemove.Add(x)
            Exit For
        End If
    Next
Next

For Each i As DataRow In rowsToRemove
    in_dt1.Rows.Remove(i)
Next

Thank you for sharing the input files @itbuddy1

You can use the vb code in the invoke code activity to get the difference records of 2 datatables.

Dim rowsToRemove = (From row1 In dt1.AsEnumerable()
                    Join row2 In dt2.AsEnumerable() On CInt(row1("CASE ID")) Equals CInt(row2("CASE ID"))
                    Select row1).ToList()
 
For Each rowToRemove In rowsToRemove
    dt1.Rows.Remove(rowToRemove)
Next

Check the below workflow for better understanding,


Output →

Hope it helps!!