I have two data tables with the same structure (the number of columns is the same and the name of columns are the same)
My first data table is named datatable1 and my second data table is named: datatable2
What I need is:
I need to compare these two data tables using three columns, and if the rows in these columns are the same then I need to delete them so the expected outcome is to have unique rows in new datatable 3 by comparing only 3 columns.
Could you please help me with this I’m very stuck and I need detailed instruction.
uniqueRows = (From row1 In datatable1.AsEnumerable()
Where Not datatable2.AsEnumerable().Any(Function(row2) row1(“Column1”).Equals(row2(“Column1”)) And
row1(“Column2”).Equals(row2(“Column2”)) And
row1(“Column3”).Equals(row2(“Column3”)))
Select row1).CopyToDataTable()
(From d In datatable1 .AsEnumerable()
Let lcs = arrColSet.Select(Function (x) d(x).ToString.Trim)
Let chk = datatable2.AsEnumerable().Any(Function (d2) arrColSet.Select(Function (x2) d2(x2).ToString.Trim).SequenceEqual(lcs))
Where Not chk
Select r = d).ToList
(From d In datatable2 .AsEnumerable()
Let lcs = arrColSet.Select(Function (x) d(x).ToString.Trim)
Let chk = datatable1.AsEnumerable().Any(Function (d2) arrColSet.Select(Function (x2) d2(x2).ToString.Trim).SequenceEqual(lcs))
Where Not chk
Select r = d).ToList
Finaly when there are rows returned
Assign Activity
dtUniqueRows | DataType: DataTable =
Dt1OnlyRows.Concat(Dt2OnlyRows ).CopyToDataTable
(From d in dtMerge.AsEnumerable()
Group d by k1=d("Column1").ToString.Trim,k2=d("Column2").ToString.Trim,k3=d("Column3").ToString.Trim into grp=Group
Where grp.Count = 1
Select r = grp.First()).CopyToDataTable
using merge datatable actvity into one datatable say mergeddt
then use mergeddt = mergeddt.AsEnumerable.GroupBy(function(x) x("FirstColumn").ToString+x("SecondColumn").ToString + x("ThirdColumn").ToString).Where(function(x) x.Count=1).SelectMany(function(x) x).CopyToDataTable