JasonS
JasonS

Reputation: 23868

How do I compare two datasets for equality

I have two datasets each with one data table pulled from different sources and I need to know if there are any differences in the data contained in the data tables. I'm trying to avoid looping and comparing each individual record or column, although there may be no other way. All I need to know is if there is a difference in the data, I do not need to know the details of any difference.

I have tried the below code, but it appears that dataset.Merge does not update rowstatus so dataset.HasChanges() always returns false. Any help is appreciated:

var currentDataSet = GetSomeData();
var historicalDataSet = GetSomeHistoricalData();

historicalDataSet.Merge(currentDataSet);

if (historicalDataSet.HasChanges()) DoSomeStuff();

Upvotes: 1

Views: 2254

Answers (1)

Henk Holterman
Henk Holterman

Reputation: 273179

I don't know of any built-in support for this and I wouldn't expect it either. So you'll have to do this by yourself in some way.

The most obvious way would be a brute force, table by table and row by row approach.

If you can rely on certain factors to be the same, ie exactly the same naming, ordering of records etc then you could test if saving both as XML and comparing the results might be an efficient trick.

Upvotes: 3

Related Questions