Jump to content
Sign in to follow this  
Jacek Laskowski

[FireDAC] Query.MergeDataset - how to use?

Recommended Posts

How to correctly use the MergeDataset method from TFDQuery?


I have FDQuery and FDMemTable, in FDMemTable I have data copied from FDQuery:


 FDMem.Data: = FDQuery.Data;


...then I modify the record in FDMemTable, and then I extract the differences to a separate FDMemTable:


FDMemDelta.Data := FDMem.Delta;  // <--- delta to data

Finally, I want to save these changes (stored in FDMemDelta as data) to the database, so I do:


FDQuery.MergeDataset(FDMemDelta, TFDMergeDataMode.dmDataMerge, TFDMergeMetaMode.mmNone);


and in FDQuery I see changes ... but I do not know how to force FDQuery to write this changes to the database.

FDQuery.Commit - does not save anything. How commit changes to DB?


Edited by Jacek Laskowski

Share this post

Link to post

To write changes to the database, try this:

LQueryDest.CachedUpdates := True;
LQueryDest.MergeDataSet( LQuerySource, TFDMergeDataMode.dmDeltaMerge );

Assert( 0 = LQueryDest.ApplyUpdates() );

LQueryDest.CachedUpdates := False;

A record will be saved if its UpdateStatus is Inserted or Modified. 

  • Thanks 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this