Comparing Datasets

N

Nate Zobrist

I am trying to write a routine to determine if my database contents have
changed. Currently this is what I do:
* Fill dataSet1 from the database and WriteXml to a file
* perform operations that may change the database
* ReadXML from the file into dataSet1
* Fill dataSet2 from the database
* Then execute this code:
dataSet2.AcceptChanges();
dataSet2.Merge (dataSet1);
bool changed = dataSet2.HasChanges();

This doesn't work. I only need to find out if the database has changed,
I don't need to know what changed (or how much was changed). Can anyone
point me in the right direction?

Thanks,
Nate
 
W

William Ryan eMVP

Check out the post below titled: "Find Differences between two DataSets" by
Senkar Nemani on 3/12
 
N

Nate Zobrist

Thanks, I saw this question previously and tried the suggestions but
neither worked.

When I try to manually iterate through each column and row, I verify
that two values are identical in the debugger but for some reason the
program always thinks they are different. My code for this is below.

The other suggestion (the one by Kevin Yu) also didn't work because I
can't guarantee that items within a row are identical. For example,
even if primary key "1" exists in both datasets, the data on that row
may have changed in one of the datasets. His solution only checks for
new and deleted rows, not updated row.

Any other suggestions?

Thanks,
Nate

*****

for (int i = 0; i < dsBase.Tables.Count; i++)
{
for (int j = 0; j < dsBase.Tables.Rows.Count; j++)
{
for (int k = 0; k < dsBase.Tables.Columns.Count; k++)
{
if (dsBase.Tables.Rows[j][k] != ds.Tables.Rows[j][k])
{
Assertion.Assert ("The database has changed!", false);
return;
}
}
}
}
 
C

Cor

Hi Nate,

It is just an idea, can you try a trick.
Save the second dataset also with write XML and read it also again and than
do your routine.
Just for a try, I am curious about the result.

Cor
 
N

Nate Zobrist

Unfortunately I get the same results. I can run diff on the files and
see that they are identical though.

Thanks for the suggestion.

- Nate
 
G

Gleb Holodov

Don't forget that you're comparing two "object"s, and thus you're doing the
reference comparison. What you need to do is to call cell1.Equals( cell2 ) -
simple and easy.

Gleb
 
N

Nate Zobrist

Argh! That was a dumb mistake for me to make. Thanks for your help, it
works great now.

- Nate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top