Jacek Laskowski 57 Posted July 29, 2019 (edited) 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 July 29, 2019 by Jacek Laskowski Share this post Link to post
f.m 8 Posted July 29, 2019 To write changes to the database, try this: LQueryDest.CachedUpdates := True; LQueryDest.MergeDataSet( LQuerySource, TFDMergeDataMode.dmDeltaMerge ); LQueryDest.Connection.StartTransaction(); Assert( 0 = LQueryDest.ApplyUpdates() ); LQueryDest.Connection.Commit(); LQueryDest.CommitUpdates(); LQueryDest.CachedUpdates := False; A record will be saved if its UpdateStatus is Inserted or Modified. 1 Share this post Link to post