Please try to use this code in invoke code activity and you should be able to get the output
First build the OutputDT with required columns and then use the invoke code
For Each row1 As DataRow In dtInput1.Rows
Dim row2 As DataRow = dtInput2.AsEnumerable().Where(Function(r) r("ID").ToString() = row1("ID").ToString()).FirstOrDefault()
If row2 IsNot Nothing Then
Dim errors As New List(Of String)
If row1("Company").ToString() <> row2("Company").ToString() Then errors.Add("Company")
If row1("Code").ToString() <> row2("Code").ToString() Then errors.Add("Code")
If row1("Name").ToString() <> row2("Name").ToString() Then errors.Add("Name")
If row1("Num").ToString() <> row2("Num").ToString() Then errors.Add("Num")
If row1("Phone").ToString() <> row2("Phone").ToString() Then errors.Add("Phone")
dtOutput.Rows.Add(row2("ID"), row2("Company"), row2("Code"), row2("Name"), row2("Num"), row2("Phone"), String.Join(", ", errors))
End If
Next
For Each row1 As DataRow In dtInput1.Rows
Dim row2 As DataRow = dtInput2.AsEnumerable().Where(Function(r) r("Company").ToString() = row1("Company").ToString()).FirstOrDefault()
If row2 IsNot Nothing Then
Dim errors As New List(Of String)
If row1("Company").ToString() <> row2("Company").ToString() Then errors.Add("Company")
If row1("Code").ToString() <> row2("Code").ToString() Then errors.Add("Code")
If row1("Name").ToString() <> row2("Name").ToString() Then errors.Add("Name")
If row1("Num").ToString() <> row2("Num").ToString() Then errors.Add("Num")
If row1("Phone").ToString() <> row2("Phone").ToString() Then errors.Add("Phone")
dtOutput.Rows.Add(row1("ID"), row2("Company"), row2("Code"), row2("Name"), row2("Num"), row2("Phone"), String.Join(", ", errors))
End If
Next
In you code (specifically the line below), does all rows in DT2 iterate for every row of DT1? For example, if DT1 and DT2 100 rows each, then would the total iterations be 10000?, for 1000 rows 1 million iterations etc?
Dim row2 As DataRow = dtInput2.AsEnumerable().Where(Function(r) r("ID").ToString() = row1("ID").ToString()).FirstOrDefault()
For Each row1 As DataRow In dtInput1.Rows
Dim row2 As DataRow = dtInput2.AsEnumerable().Where(Function(r) r("Company").ToString() = row1("Company").ToString()).FirstOrDefault()
If row2 IsNot Nothing Then
Dim errors As New List(Of String)
If row1("Company").ToString() <> row2("Company").ToString() Then errors.Add("Company")
If row1("Code").ToString() <> row2("Code").ToString() Then errors.Add("Code")
' Compare Name1
If Not (String.IsNullOrEmpty(row1("Name1").ToString()) AndAlso String.IsNullOrEmpty(row2("Name1").ToString())) Then
If row1("Name1").ToString() <> row2("Name1").ToString() Then errors.Add("Name1")
End If
' Compare Num1
If Not (String.IsNullOrEmpty(row1("Num1").ToString()) AndAlso String.IsNullOrEmpty(row2("Num1").ToString())) Then
If row1("Num1").ToString() <> row2("Num1").ToString() Then errors.Add("Num1")
End If
' Compare Phone1
If Not (String.IsNullOrEmpty(row1("Phone1").ToString()) AndAlso String.IsNullOrEmpty(row2("Phone1").ToString())) Then
If row1("Phone1").ToString() <> row2("Phone1").ToString() Then errors.Add("Phone1")
End If
' Compare Name2
If Not (String.IsNullOrEmpty(row1("Name2").ToString()) AndAlso String.IsNullOrEmpty(row2("Name2").ToString())) Then
If row1("Name2").ToString() <> row2("Name2").ToString() Then errors.Add("Name2")
End If
' Compare Num2
If Not (String.IsNullOrEmpty(row1("Num2").ToString()) AndAlso String.IsNullOrEmpty(row2("Num2").ToString())) Then
If row1("Num2").ToString() <> row2("Num2").ToString() Then errors.Add("Num2")
End If
' Compare Phone2
If Not (String.IsNullOrEmpty(row1("Phone2").ToString()) AndAlso String.IsNullOrEmpty(row2("Phone2").ToString())) Then
If row1("Phone2").ToString() <> row2("Phone2").ToString() Then errors.Add("Phone2")
End If
dtOutput.Rows.Add(row1("ID"), row1("Company"), row1("Code"), row1("Name1"), row1("Num1"), row1("Phone1"), row1("Name2"), row1("Num2"), row1("Phone2"), String.Join(", ", errors))
End If
Next
For Each row1 As DataRow In dtInput1.Rows
Dim row2 As DataRow = dtInput2.AsEnumerable().Where(Function(r) r("Company").ToString() = row1("Company").ToString()).FirstOrDefault()
If row2 IsNot Nothing Then
Dim errors As New List(Of String)
If row1("Company").ToString() <> row2("Company").ToString() Then errors.Add("Company")
If row1("Code").ToString() <> row2("Code").ToString() Then errors.Add("Code")
' Compare Name1 with Name1 and Name2, then Name2 with Name1 and Name2
If Not (String.IsNullOrEmpty(row1("Name1").ToString()) AndAlso String.IsNullOrEmpty(row2("Name1").ToString())) Then
If row1("Name1").ToString() <> row2("Name1").ToString() AndAlso row1("Name1").ToString() <> row2("Name2").ToString() Then
errors.Add("Name1")
End If
End If
If Not (String.IsNullOrEmpty(row1("Name2").ToString()) AndAlso String.IsNullOrEmpty(row2("Name1").ToString())) Then
If row1("Name2").ToString() <> row2("Name1").ToString() AndAlso row1("Name2").ToString() <> row2("Name2").ToString() Then
errors.Add("Name2")
End If
End If
' Compare Num1 with Num1 and Num2, then Num2 with Num1 and Num2
If Not (String.IsNullOrEmpty(row1("Num1").ToString()) AndAlso String.IsNullOrEmpty(row2("Num1").ToString())) Then
If row1("Num1").ToString() <> row2("Num1").ToString() AndAlso row1("Num1").ToString() <> row2("Num2").ToString() Then
errors.Add("Num1")
End If
End If
If Not (String.IsNullOrEmpty(row1("Num2").ToString()) AndAlso String.IsNullOrEmpty(row2("Num1").ToString())) Then
If row1("Num2").ToString() <> row2("Num1").ToString() AndAlso row1("Num2").ToString() <> row2("Num2").ToString() Then
errors.Add("Num2")
End If
End If
' Compare Phone1 with Phone1 and Phone2, then Phone2 with Phone1 and Phone2
If Not (String.IsNullOrEmpty(row1("Phone1").ToString()) AndAlso String.IsNullOrEmpty(row2("Phone1").ToString())) Then
If row1("Phone1").ToString() <> row2("Phone1").ToString() AndAlso row1("Phone1").ToString() <> row2("Phone2").ToString() Then
errors.Add("Phone1")
End If
End If
If Not (String.IsNullOrEmpty(row1("Phone2").ToString()) AndAlso String.IsNullOrEmpty(row2("Phone1").ToString())) Then
If row1("Phone2").ToString() <> row2("Phone1").ToString() AndAlso row1("Phone2").ToString() <> row2("Phone2").ToString() Then
errors.Add("Phone2")
End If
End If
dtOutput.Rows.Add(row1("ID"), row1("Company"), row1("Code"), row1("Name1"), row1("Num1"), row1("Phone1"), row1("Name2"), row1("Num2"), row1("Phone2"), String.Join(", ", errors))
End If
Next