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)
SQLQuery1.ApplyUpdates;
SQLTransaction1.CommitRetaining;
My SQL:
'CREATE TABLE IF NOT EXISTS "Software" (' +
'"ID" INTEGER PRIMARY KEY AUTOINCREMENT,' +
'"Name" varchar(100) UNIQUE,' +
'"AddonPath" TEXT,' +
'"TempPath" TEXT);'
My Code:
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