I’m writing a simple database editor as my first Delphi program.
I don’t have any problems with Delphi, only with the connection through the database.
I load the data in the datagrid with a -> sqlConnection -> sqlDataSet -> sqlDataprovider -> Clientdataset -> Datasource
I insert/delete records with a separate connection + SqlQuery for each.
I change the records with DBEdit
The problems occur when after I insert/delete a record, and I make a change to a record, and want to update the changes, I get the following error
Connection is busy for results from another command.
Code:
procedure TDatabaseApp.bNieuwClick(Sender: TObject);
begin
//Waardes invullen in de query statement!
SQLInsert.ParamByName('naam').asString := txtNaam2.Text;
SQLInsert.ParamByName('brouwernr').asString := txtBrouwerNR.Text;
SQLInsert.ParamByName('soortnr').asString := TXTSoortNR.Text;
SQLInsert.ParamByName('alcohol').asString := TxtAlcohol.Text;
//query
SQLInsert.ExecSQL();
SQLInsert.Close();
//Reload datagrid after record has been inserted!
Refresh();
end;
Refresh code
procedure TDatabaseApp.Refresh();
begin
//After a insert/delete query i call this statement, and changes made with the DBEdit are cancelled = temp solution.
ClientDataSet1.CancelUpdates();
SQLDataSet1.Open();
ClientDataSet1.Open();
SQLDataSet1.Refresh();
ClientDataSet1.Refresh();
end;
As your ClientDataSet is linked to your DataSetProvider and your DataSetProvider is linked to your SQLDataSet you should NEVER manipulate the SQLDataSet directly, but instead do all operations using the ClientDataSet.
So, you will have:
But i would suggest you to also use the CDS for inserts, dispensing the use of the “SQLInsert” object. This way the things will become much simpler.