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