How to copy one column from DT A to another column DT B - LINQ query

@Hiba_B

Assumptions:

  • take A Col Values when Col is not present in B
  • A and B DataTables have same row count

So we can implement a dynamic conditional side by side merge

Calculate the cols not present in B:
grafik
grafik
grafik

prepare dt 3 and add missing cols /transfer also other col settings e.g. datatype

grafik
grafik

Merge rows:
grafik

(From i In Enumerable.Range(0,dt2.Rows.Count)
Let raB = dt2.Rows(i).ItemArray
Let raA = arrMissingCols.Select(Function (x) dt1.Rows(i)(x)).toArray
Let ra = raB.Concat(raA).ToArray
Select dt3.Rows.Add(ra)).CopyToDataTable

find starter help here:
MergeTables_TakeAColIfNotInB.xaml (12.6 KB)

3 Likes