Hello I have I main datatable and want to remove another datatable if my maindata table contain this table. For this I use it “MainDataTable.AsEnumerable().Except( CheckDataTable.AsEnumerable(), DataRowComparer.Default).CopyToDataTable” But this fuction also remove my another dublicated rows. Any suggestions?
My Table:
Hi, @Murat Instead of using Except, try looping through each row in the second datatable and only remove one matching row at a time from the main datatable. This keeps duplicates in your main table as expected. The Except method removes all matches, including duplicates, so a custom loop is the way to go for your requirement
Except removes all matches, so duplicates vanish. If you need “remove only one occurrence per match,” do multiset subtraction. One LINQ, assign back to dtMain:
This keeps your remaining duplicates in dtMain and removes only the rows that appear in dt2nd, once per match. If you prefer activities, loop dt2nd, filter dtMain for each row, and remove the first match each time.