Insert/Edit in SQLite lazarus / 16-Databases ---------------------------------------------------------------------- amedeo · 2019-12-23 15:43 Help! I have no more ideas. In my application I have a form menu to start (form A), I go to a form with a TDBGrid for the list of records (form B) and from form B I go to Insert a new record or Edit a existing db record (form C). The problem cames with INSERT (for now). In the form A I have the SQLite3Connection and SQLTransaction icons to connect DB. (it's ok) In form B I have a SQLQuery and a  DataSource icon for DBGrid and this works well. In form C I have a SQLQuery to edit/receive data from Edit fields in the form. When I confirm INSERT operation I build a string with the data to set SQL.Text lTextSQL:        insert into Table1 (field1, field2, ...) value (val1, val2, ...) and after: with SQLQuery1 do begin     Close;     SQL.Text:=lTextSQL;     Open;     Insert;     Post; end [>>> this is the last version of many that I tried<<< ] in the Open instruction comes out the error         I do not understand why, Right now I feel stupid Someone knows a solution? However Merry Christmas to all Amedeo ---------------------------------------------------------------------- valdir.marcos · 2019-12-23 17:11 Quote from: amedeo on December 23, 2019, 04:43:01 pmHelp! I have no more ideas. In my application I have a form menu to start (form A), I go to a form with a TDBGrid for the list of records (form B) and from form B I go to Insert a new record or Edit a existing db record (form C). The problem cames with INSERT (for now). In the form A I have the SQLite3Connection and SQLTransaction icons to connect DB. (it's ok) In form B I have a SQLQuery and a  DataSource icon for DBGrid and this works well. In form C I have a SQLQuery to edit/receive data from Edit fields in the form. When I confirm INSERT operation I build a string with the data to set SQL.Text lTextSQL:        insert into Table1 (field1, field2, ...) value (val1, val2, ...) and after: with SQLQuery1 do begin     Close;     SQL.Text:=lTextSQL;     Open;     Insert;     Post; end [>>> this is the last version of many that I tried<<< ] in the Open instruction comes out the error         I do not understand why, Right now I feel stupid Someone knows a solution? However Merry Christmas to allFirst, give yourself some time for studying: https://wiki.freepascal.org/Lazarus_Tutorial https://wiki.freepascal.org/Lazarus_Database_Tutorial/pt   (Sorry, I could not find an English version) https://wiki.freepascal.org/SqlDBHowto https://wiki.freepascal.org/SQLdb_Tutorial0 https://wiki.freepascal.org/SQLdb_Tutorial1 https://wiki.freepascal.org/SQLdb_Tutorial2 https://wiki.freepascal.org/SQLdb_Tutorial3 https://wiki.freepascal.org/SQLdb_Tutorial4 https://wiki.freepascal.org/Category:Databases Then, if you're using Data-ware Components: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLQuery1.Edit;  // or   SQLQuery1.Insert;  // Do all the changes or add all new data you want.  SQLQuery1.Post;  SQLQuery1.ApplyUpdates;  SQLTransaction1.Commit;  SQLQuery1.Open; If not: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   SQLTransaction1.Commit;  SQLQuery1.SQL.Text := InsertTextSQL;  SQLQuery1.ExecSQL;  SQLTransaction1.Commit; ---------------------------------------------------------------------- amedeo · 2019-12-23 18:41 Thanks for the reding tips, i'll study it The problem is not resolved, a problem is still that the SQLTransaction, stated in form A is unknown in form C. Of course I have not yet made all well ---------------------------------------------------------------------- valdir.marcos · 2019-12-23 19:28 Quote from: amedeo on December 23, 2019, 07:41:17 pmThanks for the reding tips, i'll study it The problem is not resolved, a problem is still that the SQLTransaction, stated in form A is unknown in form C. Of course I have not yet made all wellIt would be easier to understand what you mean if you attach a small sample project. ---------------------------------------------------------------------- JanRoza · 2019-12-23 20:20 It sounds as if you did not include unitA in the uses clause of unitC, but all we can do is guess without you showing us some source code. ---------------------------------------------------------------------- mangakissa · 2019-12-27 08:28 Use datamodule. This unit is global and can be use in every form if the name of the datamodule is in uses.