I have to remove duplicate rows from compare two data tables in LINQ Quary
Condition: Have to check item of array
Please
Thanks
Shaik
I have to remove duplicate rows from compare two data tables in LINQ Quary
Condition: Have to check item of array
Please
Thanks
Shaik
Could you share the input and expected output data.
Try this
(From row1 In dt1.AsEnumerable()
Where Not dt2.AsEnumerable().Any(Function(row2) row1("ColumnA").ToString() = row2("ColumnA").ToString())
Select row1).CopyToDataTable()
Cheers!!
If I have 5 Cloumns , please send Quary
If you have 5 columns and you want to remove duplicate rows based on all 5 columns,
distinctRows = (From row1 In dt1.AsEnumerable()
Where Not dt2.AsEnumerable().Any(Function(row2)
row1("Column1").ToString() = row2("Column1").ToString() AndAlso
row1("Column2").ToString() = row2("Column2").ToString() AndAlso
row1("Column3").ToString() = row2("Column3").ToString() AndAlso
row1("Column4").ToString() = row2("Column4").ToString() AndAlso
row1("Column5").ToString() = row2("Column5").ToString()
)
Select row1).CopyToDataTable()
Try this:
dt1.AsEnumerable().Where(function(row) dt2.AsEnumerable().Any(function(x) x.Equals( row) )).CopyToDataTable
This will compare all the columns.
Hope it helps!!
Please try this i have modified
(From row1 In dt1.AsEnumerable()
Where Not dt2.AsEnumerable().Any(Function(row2) row1("Column1").ToString() = row2("Column1").ToString()AndAlso row1("Column2").ToString() = row2("Column2").ToString() AndAlso row1("Column3").ToString() = row2("Column3").ToString() AndAlso row1("Column4").ToString() = row2("Column4").ToString() AndAlso row1("Column5").ToString() = row2("Column5").ToString())
Select row1).CopyToDataTable()
it’s not removing any duplicate rows
Please check @lrtetala
let me check and confirm @Parvathy
Thanks
Shaik

please check @Parvathy
Input:-
dt1 -
Dt2 -
Output:-

Xaml File:-
Main.xaml (13.6 KB)
If this works for you, please mark this as a solution. So others can refer the same… ![]()
Thanks
Can you provide sample input and expected output so that I can help you.
Regards
Could you confirm this,
You want to get the rows which are not matched in DT1 and DT2, Get the unmatched rows from DT2 and append in the DT1. Am I right…?
Exactly @mkankatala
Thanks
Shaik
Okay @shaik.muktharvalli1
Follow the below steps -
→ Use the Read range workbook activity to read the Excel1 and store in a datatable called DT1.
→ Use another Read range workbook activity to read the Excel2 and store in a datatable called DT2.
→ Then use the assign activity to write the LINQ Expression,
- Assign -> dt_Output = (From row1 In DT2.AsEnumerable()
Where Not DT1.AsEnumerable.Any(Function(X) (X(0).ToString.Equals(row1(0).ToString)) AndAlso (X(1).ToString.Equals(row1(1).ToString)) AndAlso (X(2).ToString.Equals(row1(2).ToString)) AndAlso (X(3).ToString.Equals(row1(3).ToString)) AndAlso (X(4).ToString.Equals(row1(4).ToString)))
Select row1
).CopyToDataTable
→ Use append range workbook activity to append the data rows in the dt_Output to the Excel1.
Check the below workflow for better understanding,
The above LINQ Expression will works like, It will compare the two datatables and append the unmatched rows from DT2 to DT1.
Hope it helps!!