PC Review


Reply
Thread Tools Rate Thread

Comparing Datasets

 
 
Nate Zobrist
Guest
Posts: n/a
 
      15th Mar 2004
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
 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      15th Mar 2004
Check out the post below titled: "Find Differences between two DataSets" by
Senkar Nemani on 3/12


"Nate Zobrist" <zobie@zobie_NO_SPAM_.com> wrote in message
news:#(E-Mail Removed)...
> 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



 
Reply With Quote
 
Nate Zobrist
Guest
Posts: n/a
 
      15th Mar 2004
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[i].Rows.Count; j++)
{
for (int k = 0; k < dsBase.Tables[i].Columns.Count; k++)
{
if (dsBase.Tables[i].Rows[j][k] != ds.Tables[i].Rows[j][k])
{
Assertion.Assert ("The database has changed!", false);
return;
}
}
}
}
 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      15th Mar 2004
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


 
Reply With Quote
 
Nate Zobrist
Guest
Posts: n/a
 
      15th Mar 2004
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


Cor wrote:

> 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
>
>

 
Reply With Quote
 
Gleb Holodov
Guest
Posts: n/a
 
      16th Mar 2004
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


 
Reply With Quote
 
Nate Zobrist
Guest
Posts: n/a
 
      18th Mar 2004
Argh! That was a dumb mistake for me to make. Thanks for your help, it
works great now.

- Nate


Gleb Holodov wrote:
> 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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing DataSets? Leon_Amirreza Microsoft Dot NET Framework 2 16th Aug 2007 05:48 PM
Comparing Two DataSets Will Lastname Microsoft ASP .NET 19 19th Sep 2005 04:39 PM
Comparing Datasets =?Utf-8?B?SmFtZXNXaWxjZQ==?= Microsoft C# .NET 3 29th Mar 2005 04:12 PM
Comparing two datasets =?Utf-8?B?amFjZXc=?= Microsoft Dot NET 1 10th Aug 2004 08:11 AM
Comparing two datasets =?Utf-8?B?S3NoaXRpag==?= Microsoft Dot NET 3 23rd Mar 2004 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 AM.