Home All Groups Group Topic Archive Search About

Comparing two DataSets with a Merge

Author
9 Dec 2004 9:19 AM
Joe Sullivan
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
joe.sulli***@gcmweb.org
Data Systems Administrator
Great Commission Ministries

Author
9 Dec 2004 10:08 AM
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

Show quote
"Joe Sullivan" <Joe Sulli***@discussions.microsoft.com>

>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
> joe.sulli***@gcmweb.org
> Data Systems Administrator
> Great Commission Ministries
>
>
>
Author
9 Dec 2004 11:05 AM
Joe Sullivan
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

Show quote
"Cor Ligthert" wrote:

> 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
>
> "Joe Sullivan" <Joe Sulli***@discussions.microsoft.com>
>
> >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
> > joe.sulli***@gcmweb.org
> > Data Systems Administrator
> > Great Commission Ministries
> >
> >
> >
>
>
>
Author
9 Dec 2004 11:37 AM
Cor Ligthert
Joe,

I dont think that the merge will help you with that.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclassmergetopic.asp

See this row in the sample

   ' Add two rows. Note that the id column can't be the
    ' same as existing rows in the DataSet table.

What you want is in my opinion a "Match and Replacerows", which I have never
seen in ADONET.

Cor


Show quote
"Joe Sullivan" <JoeSulli***@discussions.microsoft.com>

> 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
>
> "Cor Ligthert" wrote:
>
>> 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
>>
>> "Joe Sullivan" <Joe Sulli***@discussions.microsoft.com>
>>
>> >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
>> > joe.sulli***@gcmweb.org
>> > Data Systems Administrator
>> > Great Commission Ministries
>> >
>> >
>> >
>>
>>
>>
Author
9 Dec 2004 5:51 PM
Joe Sullivan
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

Show quote
"Cor Ligthert" wrote:

> Joe,
>
> I dont think that the merge will help you with that.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclassmergetopic.asp
>
> See this row in the sample
>
>    ' Add two rows. Note that the id column can't be the
>     ' same as existing rows in the DataSet table.
>
> What you want is in my opinion a "Match and Replacerows", which I have never
> seen in ADONET.
>
> Cor
>
>
> "Joe Sullivan" <JoeSulli***@discussions.microsoft.com>
>
> > 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
> >
> > "Cor Ligthert" wrote:
> >
> >> 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
> >>
> >> "Joe Sullivan" <Joe Sulli***@discussions.microsoft.com>
> >>
> >> >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
> >> > joe.sulli***@gcmweb.org
> >> > Data Systems Administrator
> >> > Great Commission Ministries
> >> >
> >> >
> >> >
> >>
> >>
> >>
>
>
>
Author
9 Dec 2004 4:26 PM
Mark Rae
"Joe Sullivan" <JoeSulli***@discussions.microsoft.com> wrote in message
news:757BC859-52F2-4695-8F7A-50E59C9CBEF4@microsoft.com...

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

AddThis Social Bookmark Button