[SOLVED] update sqlite record in dbgrid lazarus / 16-Databases ---------------------------------------------------------------------- koloth · 2015-05-18 08:51 Helloi all, I'm building a small db app using sqlite to familiarize myself with lazarus db components, being a delphi developer for some years before. I've ran into to the following issue: In order to replicate the ttable control, i'm using a tquery containing a select * of the table in question. However although  the dbgrid displays the data correctly, every change i make is not submitted to the DB after closing the app. autoedit is enabled on  the dataset, i've tried committing the transaction and applyupdates from the query. Can someone point me to the proper way of updating a table using the dbgrid? thank you ---------------------------------------------------------------------- LacaK · 2015-05-18 18:18 Try read for example: http://wiki.freepascal.org/SqlDBHowto and related tutorials ... ---------------------------------------------------------------------- koloth · 2015-05-19 07:49 Quote from: LacaK on May 18, 2015, 08:18:51 pmTry read for example: http://wiki.freepascal.org/SqlDBHowto and related tutorials ... Thanks for the reply, I had already read that but i'm glad i was on the right track... If my understanding is correct i have to create a custom update script for the query, is there a guideline for that too? tx a lot ---------------------------------------------------------------------- mangakissa · 2015-05-19 09:27 No, that's not true. Only if you using joins in your table it's necessary using updateSQL. The most important thing is the following procedures: - post - applyupdate - commit(retaining) ---------------------------------------------------------------------- koloth · 2015-05-20 09:36 Quote from: mangakissa on May 19, 2015, 11:27:12 amNo, that's not true. Only if you using joins in your table it's necessary using updateSQL. The most important thing is the following procedures: - post - applyupdate - commit(retaining) On which dbgrid event should the procedure be applied to? thank you.. ---------------------------------------------------------------------- LacaK · 2015-05-20 11:45 Quote from: koloth on May 20, 2015, 11:36:36 am On which dbgrid event should the procedure be applied to? I would use TDataSet.AfterPost event. Not any TDBGrid event! ---------------------------------------------------------------------- koloth · 2015-05-20 12:50 I would use TDataSet.AfterPost event. Not any TDBGrid event! [/quote] In't it a bit weird to run : Code: [Select]- post - applyupdate - commit(retaining) in the afterpost event? will it ever run? ---------------------------------------------------------------------- LacaK · 2015-05-20 19:18 Of course not "Post" in "AfterPost" event handler. DB-aware controls like DBGrid or DBNavigator are calling Post. Which is okay. But I would use remaining 2 calls "ApplyUpdates" and "Commit" in AfterPost (best in DataModule) So you will have isolated "presentation of data" (forms) and "background data manipulation/interaction with database") ---------------------------------------------------------------------- koloth · 2015-05-25 09:13 thanks for your help guys, finally nailed it! moving on to updating joined queries...