Data Table Comparison based on a specific column

Hi all,

I want to compare table 1 with table 2 based on a specific column. Then copy the new data rows available in table 2 to table 1.
i am using below code.
Not table1.AsEnumerable().Select(function® r.Field(Of Int32)(‘Email’)).Any(function(x) x = row.Field(Of Int32)(‘Email’))).CopyToDataTable()

But using this code if there any data in table1 but not in table 2 that is also coming. which should not.
Please help

Try for each row in dt2 lookup value on key in dt1, then if condition is/isnot met add data row to dt1.

1 Like

thanks matt. i just want it via linq code.

Are you sure the field “Email” is an integer? That seems strange, I would have expected that to be a string field.

you are correct thats wrongly typed. thats string actually.

dt2.AsEnumerable().Where(Function(row) Not dt1.AsEnumerable().Select(Function® r(“Col1”).toString).Any(Function(x) x = row(“Col1”).toString)).CopyToDataTable()

In this dt1 contains 10 to 14 numbers and dt2 contains 12,15

The Output is 15

Thanks @Priyanka_Ramesh for your response. But this is the same code i have written. i am getting rows from dt1 as well. can you please recheck?

Hi ,
yes, Can you check in this XAML . I’m not getting dt1 in (9.4 KB)


Oh sorry its my bad. there is some issue in my data. Code is correct only. Thanks for all your effort.

1 Like