[Solved] DBGrid, SQLQuery1.ApplyUpdates Return error message lazarus / 16-Databases ---------------------------------------------------------------------- TheLastCayen · 2018-10-29 12:13 Hi, I am using Windows 7 64b Lazarus 1.8.4 FPC 3.0.4 sqlite-dll-win64-x64-3250200 I have a DBGrid and 3 DBEdit connect to my Table. I am able to Append new record But I can't update existing one . I am following this tutorial http://wiki.freepascal.org/SQLdb_Tutorial2 and I can't figure what I am missing. I am using the same Save Button to save the record I append and the record I try modify. The following 2 lines return the error message:  An Error Occurred while applying the updates in a record: DBConnection: No Update query specified and failed to generate one.(No fields for inclusion in where statement found) 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.ApplyUpdates;  SQLTransaction1.CommitRetaining; My SQL: 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         'CREATE TABLE IF NOT EXISTS "Software" (' +        '"ID" INTEGER PRIMARY KEY AUTOINCREMENT,' +        '"Name"  varchar(100) UNIQUE,' +        '"AddonPath" TEXT,' +        '"TempPath" TEXT);' My Code: 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 Procedure TFSoftware.RefreshDB;begin  SQLQuery1.Close;  SQLQuery1.SQL.Text := 'SELECT Name,AddonPath,TempPath FROM Software;';  DBConnection.Connected := True;  SQLTransaction1.Active := True;  SQLQuery1.Open;   DBGrid1.Options := DBGrid1.Options - [dgTitles, dgIndicator];  DBGrid1.ScrollBars:=ssAutoVertical;  DBGrid1.Columns[0].Width:=DBGrid1.Width-20;  DBGrid1.Columns[1].Visible:=False;  DBGrid1.Columns[2].Visible:=False;end;     Procedure TFSoftware.CloseDB;begin  SQLQuery1.Close;  SQLTransaction1.Active := False;  DBConnection.Connected := False;end;   procedure TFSoftware.FormActivate(Sender: TObject);begin  DBConnection.DatabaseName := Form1.DBNAME;  DBConnection.Transaction := SQLTransaction1;  SQLQuery1.DataBase := DBConnection;  DataSource1.DataSet := SQLQuery1;  DBGrid1.DataSource := DataSource1;   DBEdit1.DataSource := DataSource1;  DBEdit2.DataSource := DataSource1;  DBEdit3.DataSource := DataSource1;  DBEdit1.DataField := 'Name';  DBEdit2.DataField := 'AddonPath';  DBEdit3.DataField := 'TempPath';   RefreshDB;end;    procedure TFSoftware.BTAddClick(Sender: TObject);begin  DBGrid1.DataSource.DataSet.AppendRecord([null]);   end;     procedure TFSoftware.BTCancelClick(Sender: TObject);begin  RefreshDB;end;   procedure TFSoftware.BTSaveClick(Sender: TObject);begin  SQLQuery1.ApplyUpdates;  SQLTransaction1.CommitRetaining;end; Anyone see what I am doing wrong? Thank you ---------------------------------------------------------------------- rvk · 2018-10-29 12:23 Quote from: TheLastCayen on October 29, 2018, 01:13:16 pmThe following 2 lines return the error message:  An Error Occurred while applying the updates in a record: DBConnection: No Update query specified and failed to generate one.(No fields for inclusion in where statement found) What is the Upda]"]>Blockedde for the SQLQuery1? If it's upWhereKeyOnly you need to add the ID in your SELECT. Otherwise SQLQuery1 doesn't know what ID it must update. So you can either add the primary key to the SELECT (preferred) or set the Upda]"]>Blockedde to upWhereAll. (You can hide or delete the ID-column from the DBGrid if you want.) ---------------------------------------------------------------------- TheLastCayen · 2018-10-29 19:10 Thank you rvk, You fixed my issue. I am happy to know I have to add the ID. I think I lost a few hair on that issue  For future Reference, this is what I changed in my code: 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 Procedure TFSoftware.RefreshDB;begin  SQLQuery1.Close;  SQLQuery1.SQL.Text := 'SELECT * FROM Software;';  DBConnection.Connected := True;  SQLTransaction1.Active := True;  SQLQuery1.Open;   DBGrid1.Options := DBGrid1.Options - [dgTitles, dgIndicator];  DBGrid1.ScrollBars:=ssAutoVertical;  DBGrid1.Columns[0].Visible:=False;  DBGrid1.Columns[1].Width:=DBGrid1.Width-20;  DBGrid1.Columns[2].Visible:=False;  DBGrid1.Columns[3].Visible:=False; end;