PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET DataSet - GetChanges() and Merge() Questions

Reply

DataSet - GetChanges() and Merge() Questions

 
Thread Tools Rate Thread
Old 22-06-2006, 04:36 PM   #1
=?Utf-8?B?SmltSHVz?=
Guest
 
Posts: n/a
Default DataSet - GetChanges() and Merge() Questions


I need to collect a "delta" between two Datasets: DS1 and DS2. DS2 was
created from DS1.

We cannot use/rely on RowState because of the operations involved in
generating DS2. Essentially all rows/columns are deleted and most are
re-added.

Can I use Merge between DS1/DS2 to generate a "Delta" Dataset? Something like:

DS1=DS2.Copy();
....
// Code that extensively modifies the DS2 Dataset
....
DS1.AcceptChanges(); // Reset RowState info - it is useless
DS2.AcceptChanges(); // Reset RowState info - it is useless
DS1.Merge(DS2, true);
sChanges = DS1.getChanges().GetXML();

I end up geting some XML - but it seems to bear little relation to the
changed area of the DataSet. Perhaps the RowState is killing me... is there a
way to get GetChanges() to work even if RowState is not valid?

It appears Merge() requires a Primary Key in order to detect row changes vs.
additions. Are there other limitations to using Merge?

Sorry for such a generic request. Worst case I will walk thru each table in
the Dataset determining changes/adds/etc... but I hate to do this if it's
already covered in the existing methods.

Thanks.

Jim
  Reply With Quote
Old 22-06-2006, 07:00 PM   #2
=?Utf-8?B?SmltSHVz?=
Guest
 
Posts: n/a
Default Re: DataSet - GetChanges() and Merge() Questions

Carl,

I over-simplified in order to present as quickly as possible. A bad idea ;-(

Basically our dataset of tables are each 'dis-assembled' with most rows
becoming columns and vise-versa. The UI allows the users to add in new
'columns' or delete existing 'columns' in the UI. These columns actually
correspond to rows in the original Dataset.

But essentially once we have converted thru this row->columns, edits,
columns->rows routines -- all rows in the Dataset are flagged as Added - even
if there were no 'net' changes to them.

So the RowState has to be disregarded: The Dataset we get back will have the
exact same schema as the original (and most of the data) but is a completely
new set of tables.

> Jim,
> Why are you making a copy of DS1 and modifying DS2? Why not just modify DS1?
>


Again - bad communication from trying to be terse...this code snippet should
be more clear.


dsOriginal=dsLive.Copy();
....
// Code that extensively modifies the dsLive() Dataset
....

// Flag initial state as clean
dsLive.AcceptChanges();
dsOriginal.AcceptChanges();

// Merge in the changes from dsLive:
// this should not only give us the ds changes, but
// the apropriate RowState for those changes also.
dsOriginal.Merge(dsLive, true);

// GetChanges() should present us with a 'delta' between the DataSets
sChanges = dsOriginal.getChanges().GetXML();

Steps
------
o dsOriginal contains the DataSet prior to any changes.
o dsLive is the final DataSet after modifications.
o Reset the RowState
o Merge should result in the differences being moved into
dsOriginal and flagged with viable RowStates.
o Use GetChanges() to list off the 'delta'


Jim

"Carl Prothman" wrote:
> Also, how are you obtaining DS1? If you are using a Select statement, then the RowState should be Unchanged. Or if you are adding rows to the DataTable, then you should call AcceptChanges() after the inserts. Then if you make changes (add, modify, delete), the RowState should change. You can use GetChanges() to geta a copy of the DataTable containing all changes made to it since it was last loaded or AcceptChanges() was called. Is this not working for you?
>
> Note if you use .NET framework 2.0, then you can set RowState by use the DataRow's SetModified() and SetAdded() methods.
> http://msdn2.microsoft.com/en-us/sy...etmodified.aspx
> http://msdn2.microsoft.com/en-us/sy...w.setadded.aspx
>
> --
>
> Thanks,
> Carl Prothman
> Microsoft ASP.NET MVP
> http://www.CarlProthman.NET
>


  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off