Compare collections

CamiCat

Member
Hello friends,

I need to compare two collections.
I need to find if in the main collection are already present the rows of another collection.
In positive case, I need to delete the row of the second colleciton from the main collection.
How to do that?
Thank you so much,
Cami
 

sivagelli

Well-Known Member
The following code helps in removing the rows from the collection that are present in other collection IFF both have same column names.

Achieved using VB and Linq. Have the below references and namespaces-
References:
System.dll
System.Data.dll
System.Drawing.dll
System.xml.dll
System.Data.DataSetExtensions.dll
System.Core.dll

Namespace:
System
System.Data
System.Drawing
System.Collections.Generic
System.Linq

Create an object with Code stage that accepts two collections as inputs- 'Main' & 'Second'. The 'output' will be a collection having rows of Main collection that are not present in Second collection.

Code:

Code:
output = Main.AsEnumerable.Except(Second.AsEnumerable, DataRowComparer.Default).CopyToDataTable()

Post back how it goes!
 
Top