Insert Into and Edit Database lazarus / 16-Databases ---------------------------------------------------------------------- Weitentaaal · 2020-11-04 09:18 Hey Guys, just wanted to ask whats the best / correct way to do this 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                   dbGer.Insert;                    dbGer.FieldByName('Zeichnung').AsInteger := ZeichNr;                  dbGer.FieldByName('ZlAl').AsInteger := InZlAl;                    dbGer.FieldByName('Komp').AsInteger := 1;                    dbGer.FieldByName('Art').AsInteger := 0;                    dbGer.FieldByName('X1').AsFloat := RsX;                    dbGer.FieldByName('X2').AsFloat := ReX;                    dbGer.FieldByName('Y1').AsFloat := RsY;                    dbGer.FieldByName('Y2').AsFloat := ReY;                    dbGer.FieldByName('Z1').AsFloat := RsZ;                    dbGer.FieldByName('Z2').AsFloat := ReZ;                    If InZlAl = 0 then Begin                       dbGer.FieldByName('ZRahmenart').text := ZRahmenart;                  End Else Begin                       dbGer.FieldByName('ARahmenart').text := ARahmenart;                  End;                    dbGer.FieldByName('Para1').text := 0;                  dbGer.ApplyUpdates;  DB : Sqlite Edit: I Tested to Edit a Fiel in my db in a mini Project : 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   wgrExecute(dbT, 'SELECT * FROM GERAET WHERE Zeichnung = 1 AND Komp = 0 AND Art = 1');  dbT.Edit;  dbT.FieldByName('ARahmenart').AsInteger:= 2;  dbT.Post;  dbt.ApplyUpdates;  showMessage('t3');  did't work what am i doing wrong ? Getting this Error ---------------------------------------------------------------------- JanRoza · 2020-11-04 11:07 Shouldn't there be a dbGer.Post statement before the ApplyUpdates? ---------------------------------------------------------------------- Weitentaaal · 2020-11-04 11:31 i dont know if i need it .. just a Beginner asking how to do this in a better way ---------------------------------------------------------------------- JanRoza · 2020-11-04 12:18 You need the post statementafter an edit or insert statement, take a look at https://wiki.freepascal.org/SqlDBHowto. ---------------------------------------------------------------------- Weitentaaal · 2020-11-06 06:55 didn't work with the .Post :/ i set the query to edit --> then i edit the field in db --> after that i use Post and after the Post i apply the updates but i am making an mistake i don't know wich ... pls help ---------------------------------------------------------------------- Zvoni · 2020-11-06 07:26 Transaction commit? ---------------------------------------------------------------------- Weitentaaal · 2020-11-06 07:33 so i should just add an Commit after alll ? or how do u mean this ? ---------------------------------------------------------------------- egsuh · 2020-11-06 07:41 Try these steps. Transaction.Active := true; // Then do what you have written Transaction.Commit; Transaction.Active := True; // Open DBT                    ==> You should be able to see your changes here ---------------------------------------------------------------------- Weitentaaal · 2020-11-06 07:51 Changed Code o this but didn't work:( : 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    initdb(); //initDb:   sqlConnWGR := TSQLite3Connection.Create(Nil);   sqlConnWGR.DatabaseName := SQLiteWGRPath;   //sqlConnWSET.HostName := SQLiteDBHost;   //sqlConnWSET.UserName := SQLiteDBUser;   sqlConnWGR.Password := SQLiteWGRPass;   sqlConnWGR.Connected := true;   sqlConnWGR.KeepConnection := true;    SQLTransWGR := TSQLTransaction.Create(sqlConnWGR);   sqlConnWGR.Transaction := SQLTransWGR;//End InitDb      dbT := TSQLQuery.Create(nil);  dbT.UsePrimaryKeyAsKey := False;  dbT.DataBase := sqlConnWGR;  dbT.PacketRecords := -1;  SQLTransWGR.Active:= True;  //dbT.SQL.Text := 'Update Geraet Set Zeichnung = '+Char(32)+'1'+Char(32)+' WHERE KOMP=0 AND ART=0';  wgrExecute(dbT, 'SELECT * FROM GERAET WHERE Zeichnung = 1 AND Komp = 0 AND Art = 1');  dbT.Edit;  dbT.FieldByName('ARahmenart').AsInteger:= 2;  dbT.Post;  //dbt.ApplyUpdates;  SQLTransWGR.Commit;   i Know how to add stuff and its working but i cant Edit a Already existing field any Ideas ? Thanks btw for ur Help ---------------------------------------------------------------------- egsuh · 2020-11-06 08:06 You need to run applyupdates. "Post" changes the content of "opened dataset" ---  dbT here, but does not change the content of database in the HardDisk. ApplyUpdates does.  The procedures must be so. But I'm not sure whether you can change the content of TSQLQuery. If you are using SQLite, then try TSQLite3DataSet. It's on Data Access Tab. ---------------------------------------------------------------------- Weitentaaal · 2020-11-06 08:56 Pls Help i dont know what i am missing 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 try    sqlConnWGR := TSQLite3Connection.Create(Nil);    sqlConnWGR.DatabaseName := SQLiteWGRPath;    //sqlConnWSET.HostName := SQLiteDBHost;    //sqlConnWSET.UserName := SQLiteDBUser;    sqlConnWGR.Password := SQLiteWGRPass;    sqlConnWGR.Connected := true;    sqlConnWGR.KeepConnection := true;     SQLTransWGR := TSQLTransaction.Create(sqlConnWGR);    sqlConnWGR.Transaction := SQLTransWGR;     dbT := TSQLQuery.Create(Nil);    dbT.DataBase := SQLConnWGR;    dbT.SQL.Text := 'SELECT * FROM GERAET WHERE ZEICHNUNG = 1 AND KOMP = 0 AND ART = 0;';    dbT.Open;    dbT.Edit;     dbT.FieldByName('Zeichnung').AsInteger := 2;     dbT.Post;    dbT.Upda]"]>Blockedde := upWhereAll;    //SQLTransWGR.Commit;    dbT.ApplyUpdates;     dbT.Close;    dbT.Free;  except    on e:Exception do begin      showmessage(e.Message);    end;  end;   sqlConnWSET.Close();  SQLTransWSET.CloseDataSets;  it tells my my db is locked and i cant update the table but i never used a second connection to the db:( is there any way its opened somewhere else ? ---------------------------------------------------------------------- Weitentaaal · 2020-11-06 09:14 error Because i had the db browser open . Fixed but i get External SIGSEV when closing Connection :/ ---------------------------------------------------------------------- egsuh · 2020-11-06 10:22 The order should be as follows.    SQLTransWGR.Active := True;    dbT.Open;    ......    dbT.ApplyUpdates;    SQLTransWGR.Commit;    // This closes all the linked datasets. ---------------------------------------------------------------------- JanRoza · 2020-11-06 14:09 Or use 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 SQLTransWGR.CommitRetaining;    // Does not closes all the linked datasets. If you want to keep the dataset open after the commit.