sample data there is 1 unmatched record in excel which i need to get as my output.
-
1Can you share more info? Do I understand it that you have two collections and you would like to get the ones that are in one table but not the other? What have you tried so far? – Marek Stejskal Nov 07 '18 at 09:26
-
I need to get unmatched records from both collections, one source is Excel Data and other source is DB2OLEDB table data, both have the same columns but sometimes some columns data do not match to other, so i need to compare both sources data and send the unmacthed data in to excel sheet. added sample data image pls let me know if you need more details. – madhu Nov 08 '18 at 19:32
1 Answers
There are two options I can think of from the top of my head:
- Simple way
- Coding way
Doing it the simple way would be looping through the larger of the two collections and using the Filter Collection
from Utilities - Collection manipulation
on the other collection to see if a row with the same values as in the primary collection is in the other collection. This approach will work well, but it will require an unnecessary amount of stages, more time to build and the performance will suffer in case you have large collections.
Doing it the coding way would mean using either VB.NET or C# and using the Except
command. There are several examples even here on Stack Overflow (example). The drawback of this solution is that some background knowledge of .NET is required. You would need to add additional DLL references (System.Data.DataSetExtensions.dll
and System.Core.dll
) and namespaces (System.Linq
).
The C# code then would be:
colOut = col1.AsEnumerable().Except(col2.AsEnumerable(), DataRowComparer.Default).CopyToDataTable();
...where col1 and col2 are input collections and colOut is an output collection.
Mind you that you that the code above will find you rows from col1 that are not present in col2, to find rows from col2 that are not present in col1 you will either have to switch the inputs and run it again or tweak the code some more.

- 2,698
- 1
- 20
- 30