I need help to solve this. i have 2 excel file like Old Data and New data both have common column. unique identifier is email id. now i want to find which row is change and get write in new data sheet2. upload below screenshot for your refence.
' Clone the structure of dtNew for output
dtChanges = dtNew.Clone()
' Loop through each row in the new data
For Each newRow As DataRow In dtNew.Rows
Dim email As String = newRow("Email").ToString.Trim()
' Find matching row in old data
Dim oldRow As DataRow = dtOld.AsEnumerable() _
.FirstOrDefault(Function(r) r("Email").ToString.Trim() = email)
' If match found, compare columns
If oldRow IsNot Nothing Then
Dim isChanged As Boolean = False
For Each col As DataColumn In dtNew.Columns
If col.ColumnName <> "Email" Then
Dim newVal As String = newRow(col.ColumnName).ToString.Trim()
Dim oldVal As String = oldRow(col.ColumnName).ToString.Trim()
If newVal <> oldVal Then
isChanged = True
Exit For
End If
End If
Next
If isChanged Then
dtChanges.ImportRow(newRow)
End If
End If
Next
You can use a simple Query dt_result = dt_input.AsEnumerable().Where(Function(x) Not dt_output.AsEnumerable().Any(Function(y) y.ItemArray.SequenceEqual(x.ItemArray))).CopyToDataTable()