Question

Is there any way to manually track the changes done to a clientdataset's delta and update the changes manually on to then db. i have dynamically created a clientdataset and with out a provider i am able to load it with a tquery, now user will do some insert update and delete operations on the data available in the cds, and at final stage these data(modified) should be post in to database by using a tquery(not apply updates)..

Was it helpful?

Solution

After populating your data set from the TQuery call MergeChangeLog so that the records do not stand out as newly inserted, and be sure that LogChanges is set.

Then when at the final stage, before updating the query with the dataset, set StatusFilter so that only the records that you want to take action on should be showing. For instance;

ClientDataSet1.StatusFilter := [usDeleted];

You can also use UpdateStatus on a record to see if it has been modified etc..

But be careful that, is seems that there will be multiple versions of a record, and it is a bit difficult to understand how the "change log" keeps track. And there also can be multiple actions on a record, like modifying it a few times and then deleting it.

OTHER TIPS

Change:= TPacketDataSet.create;

Change.Data:= YourClientDataSet.Delta;
while not Change.Eof do
begin
 Change.InitAltRecBuffers(False);
 if Change.UpdateStatus = usUnmodified then
   Change.InitAltRecBuffers(True);

 case Change.UpdateStatus of
  usModified:  ;//your logic read codes in Provider.pas for further hint
  usInserted:  ;//your logic read codes in Provider.pas for further hint
  usDeleted: ;//your logic read codes in Provider.pas for further hint
 end;

 Change.Next;
end;

Above should work regardless of number of modified Cheers Pham

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top