I want to compare field values of two datatable say dt1 and dt2 from sql server. After comparison if any field value is different then I have to copy that field from dt1 to another data table say dt3. Please help on this
In above scenario, 1st row has country different and 2nd row has name different So after comparison dt3 should contain as below
Dt3 should copy from dt1 always in case any field value is different. Also suppose Dt1 contains any null value then it should not compare with dt2. But if dt2 contains null value then it should copy that field from dt1 to dt3.
In a nutshell: any value which is different or blank in dt2 needs to output into dt3 with respective field value of dt1
I hope I made my question clear
@Sana_Afreen Can you maybe provide some more examples with more rows ?
As we could see the resultant DT, But I do think you would need to explain it more elaborately as to why you have got the resultant values.
Can you explain How was ‘India’ placed in the First row 2nd Column and ‘fgh’ in the Second row first column ?
Hi Arpan, Thanks for the reply
Here Name and country are column names.
India is in first row because bot has compared 1st row of dt1 and dt2 and it found that value of name column is same but value at country column is different. so in resultant output table it has copied dt1 value “India”. As India belongs to country column it has pasted there
So where ever values are different I need to output it to dt3 with the dt1 values
@Sana_Afreen But If you compare the Second rows of both DT1 and DT2, the resultant according to the logic you have provided would be ‘Xyz’ instead of ‘fgh’. Since we need to take the values from DT1, isn’t that right ?
Also please provide examples with more rows if possible
yes true. Sorry my mistake
here nothing is copied from 1st row as data is equal in both dt1 and dt2
from 2nd row, as country is different so it copied “India” from dt1 to dt3
from 3rd row, as Null is there so it simply pasted “India” from dt1 to dt3
from 4th row, as name is different and country is null in dt2, bot has pasted “AMQ” and “India”
@Sana_Afreen Can you check the below Workflow :
Comparison.zip (2.5 KB)
As we have understood, we would need to compare the rows sequentially one row from one Datatable with one row from another Datatable. I have used Skip and Take Methods to retrieve only the Corresponding row and used and If condition to update the values as needed.
However, this works only when you have to compare and update two column values.
Let us know if it didn’t help and please revert back if it was not the expected solution.
this file is not getting downlaod
@Sana_Afreen Are you still facing the issue in Downloading ?