Linq query not working to copy values between two datatables

Is it possible with Linq to copy data from specific column of a Datatable say InputDT to specific column of Datatable OutputDT which also has a condition needs to be checked before copying. Condition is to check if data we are copying from InputDT to specific cell of OutputDT is already present in OutputDT or not. If present, overwrite the data, else append below.I tried the query mentioned below, no luck.

(From a In OutputDT.AsEnumerable() Select InputDT.LoadDataRow (new Object() {If(a.Field(Of String)(“PHONE NO”)=not a.Field(Of String)(“PHONE NO”), a.Field(Of String)(“PHONE NO”),a.Field(Of String)(“PHONE NO”)) },False)).CopyToDataTable

If you need to compare specific cell values, the best way to go is with a foreach, if not, maybe some kind of join between the two tables.

For Each takes more time to execute if the record count is high.


Can you share sample input and output. It appears from your question that you want unique values of a column.