I keep getting the following error when I try to insert a record in a table in a Firebird 2.5 database - Dataset Error: Operation not allowed, dataset"%s" is not in an edit or insert state state
I'm using the following procedure below to set up the SQL statements in the TSQLQuery components. The workWith is a global variable in the form which is set when the form is created.
procedure TOrganisationFrm.SetupDatasets;
begin
TopQry.Active := False;
WorkingQry.Active := False;
WorkingQry.deletesql.Text := 'execute procedure deleteOrg (:OrgId)';
case workWith of
'Directorate':
begin
With WorkingQry do
begin
SQL.Text := 'select ORGID, ORG_NME AS Name, LEVEL_NUM, PARENT, ';
SQL.Text := SQL.Text + 'INUSE from organisation WHERE Parent IS NULL ';
SQL.Text := SQL.Text + 'ORDER BY Name;';
InsertSQL.Text := 'execute procedure insertorg (:OrgName, 1, NULL)';
Active := True;
end;
end;
'Division':
begin
With WorkingQry do
begin
SQL.Text := 'select ORGID, ORG_NME AS Name, LEVEL_NUM, ';
SQL.Text := SQL.Text + 'PARENT, INUSE from organisation WHERE ';
SQL.Text := SQL.Text + 'LEVEL_NUM=2 AND PARENT = :ORGID ';
SQL.Text := SQL.Text + 'ORDER BY Name;';
InsertSQL.Text := 'execute procedure insertorg (:OrgName, 2, :OrgParent)';
DataSource := TopDsr;
end;
With TopQry do
begin
SQL.Text :='select ORGID, ORG_NME AS Name, LEVEL_NUM, PARENT, ';
SQL.Text := SQL.Text + 'INUSE from organisation WHERE LEVEL_NUM = 1 ';
SQL.Text := SQL.Text + 'ORDER BY Name;';
end;
TopQry.Active := True;
WorkingQry.Active := True;
end;
end;
end;
I am using the following procedure to try to insert a new record.
procedure TOrganisationFrm.Button1Click(Sender: TObject);
begin
WorkingQry.Append ;
WorkingQry.FieldByName('Name').AsString := AddEdt.Text; // Error message gets triggered here
WorkingQry.Post;
GovDM.GovTrnMain.Commit;
end;
From what I've read issuing using the statement "WorkingQry.Append;" should have place the dataset in insert mode. I have also tried WorkingQry.Insert and get the same error.