Comparing two DataSets with a Merge

G

Guest

I am trying to find the difference between two datasets. I have tried
merging the two datasets and then writing an xml diffgram like so:

dsA.AcceptChanges();
dsA.Merge(dsB, true);
dsA.WriteXml("D:/dev/Changes.xml", XmlWriteMode.DiffGram);

It would make sense that the merge would only change the records in dsA that
are different from dsB. However, when I look at the XML file, it is showing
every row as "modified" event when the previous and current values are the
same.

Am I doing something wrong here, or will it always show every row as
modified when I execute the merge method. Or, does someone know of a better
way to show differences between two similar datasets. I am trying to aviod
parsing through every row if at all possible.

Thanks,
Joe Sullivan
(e-mail address removed)
Data Systems Administrator
Great Commission Ministries
 
C

Cor Ligthert

Joe,

Merging from two datasets to compare should be always impossible.
The tables that has to be merged needs the same primary key at least and
there should not be the same key in the destiniation table as in the sending
table.

Your code makes now probably only an extra table in your dataset.

A dataset is an object that holds tables objects, which hold row objects,
which holds item objects.

So that easy is it not to compare.

Therefore what is it you want to compare?

Cor
 
G

Guest

What I am attempting to do is update data on our live sql server that has
been changed over time offsite and saved in an access database. I can't just
call the GetChanges() method of the dataset because I want to make sure that
I get all changes across multiple runs of the application (this is an offline
application that may not always be running).

I am attempting to create an XML file that contains only changes to the
data. I figured that I could save the changes across multiple runs in the
access database. Then, when I am ready to synchronize with our database on
the server, I could load the live data into a dataset and compare it with the
dataset from the access database to just return the changed data (I cannot
update the tables through SQL code... I have an api that I am going to run
through the changes with).

For example, say that we have changed the third column of the 1st row in my
offline access system....

In dsLive,
1, "John Doe", 100
2, "Jane Doe", 200

in dsAccess:
1, "John Doe", 200
2, "Jane Doe", 200

I want a resulitng dataset that shows the changed row:
current version: 1, "John Doe", 200
previous version: 1, "John Doe", 100

Which is what I hoped to see in dsLive by calling dsLive.Merge(dsAccess).

All I want to do is to update the live dataset with the access dataset and
take advantage of versions in the dataset to compare previous and current
versions.

Thanks,
Joe
 
M

Mark Rae

What I am attempting to do is update data on our live sql server that has
been changed over time offsite and saved in an access database. I can't
just
call the GetChanges() method of the dataset because I want to make sure
that
I get all changes across multiple runs of the application (this is an
offline
application that may not always be running).

In a nutshell, are you trying to fetch a dataset from one recordsource and
then see if each record exists (by primary key comparison) in another
recordsource? If not, then add the record to the destination recordsource,
if yes, then update the destination recordsource with the values from the
source recordsource?

If so, then I have just written exactly that for mySQL and SQL Server, but
the code should be virtually identical...
 
G

Guest

I am not adding any rows. Forget about adding rows. In my example, I am
CHANGING a row. An ADO.NET RecordSet keeps track of the previous and current
values when a recordset row changes. You can then call the GetChanges()
method to return only the rows that have been changed (the recordset keeping
track of the previous and current values). I could effectively end up with
the kind of merge I want if I looped through the rows of the first dataset
and updated any columns that were different from the second dataset and then
called the GetChanges method. However, I am trying to avoid looping through
the rows. Again, the end result here is a dataset containing only the
changes.

Thanks for your help,
Joe
 

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