Rewrite the values of a column in DataTable LINQ or Lambda


I compare two DataTables usig the the syntax provided by @ppr which works exactly as expected

(From d in dt1.AsEnumerable
Let raf = d.ItemArray.Take(8)
Let chk = dt2.AsEnumerable.Any(Function (d2) d2.ItemArray.Take(8).SequenceEqual(raf))
Where not chk
Select r =d).CopyToDataTable

The thing is that some times the data from the fourth column of one of the DataTables (which contains a date) is interpreted as a DateTime like “15/12/2023 00:00:00”

So I need to keep just the first 10 characters for this column.
I see 2 approaches :

  • Use substring method in order to keep the 10 first characters
  • Parse the date to string using the format (“dd/MM/yyyy”)

Would you have a LINQ to perform that ?


Can you try using below LINQ expression:

(From d In Datatable1.AsEnumerable
 Let raf = d.ItemArray.Take(3).Concat({d.Field(Of String)(3).Substring(0, 10)}).Concat(d.ItemArray.Skip(4))
 Let chk = Datatable2.AsEnumerable.Any(Function(d2) d2.ItemArray.Take(8).SequenceEqual(raf))
 Where Not chk
 Select r = d).CopyToDataTable

Hope it helps!!

Thank you @mkankatala
The detail is that the dt have more than 8 columns, but the comparison is performed on the 8 first columns.
So the exclusion is not performed in this case.

looks more

  • that only 1 side from the SequenceEqual is defensive handling it
  • that after skip(1) a Take is missing

Just do on thing,
share some samples from dt1, dt2 and we check for an adapted solution strategy