Home > Back-end >  Delphi is used adodataset connect to the database is an error
Delphi is used adodataset connect to the database is an error

Time:10-20

Error
Project Project1. Exe raised exception class EDatabaseError with message 'ADODataSet1: always perform this operation on a closed dataset'. Process stopped. Use Step or Run to continue.
The original code
Procedure TForm3. SpeedButton1Click (Sender: TObject);
The begin
If (edit1. Text=' ') or (edit2. Text=' ') or (edit3. Text=' ') then
Showmessage (' Data is not enough! ')
The else
The begin
With adodataset1 do
The begin
Insert;
Fieldbyname (' building number '). AsString:=edit1. Text;
Fieldbyname (' building dish names.) AsString:=edit1. Text;
Post;
Refresh;
end;
end;

end;

To solve the

CodePudding user response:

The breakpoints, and see what other errors, is the post office, or refresh, post up, why do you want to refresh

CodePudding user response:

Hint as if this place has a problem of fieldbyname (' building number). AsString:=edit1. Text;
Don't know why

CodePudding user response:

Insert before, data is in open state,

CodePudding user response:

Add adodataset1. Active:=true;
Or use the adodataset1. Open;

CodePudding user response:

'ADODataSet1: always perform this operation on a closed dataset', understand the English meaning will understand, ADODataSet1 can't this operation on a closed recordset,
So, there should be a
With adodataset1 do
The begin
adodataset1. The Open ();//add here, including adodataset1. Sql. The Text can't be empty
Insert;
Fieldbyname (' building number '). AsString:=edit1. Text;
Fieldbyname (' building dish names.) AsString:=edit1. Text;
Post;
Refresh;
end;


CodePudding user response:

The building Lord, DataSet before operate should write Sql statements first, and then Open,
Before the execution of this event should first open a DataSet, such as:
ADODataSet. Sql. Text:='Where the Select XXX from XXX XXX';
ADODataSet. Open;
Then
Procedure TForm3. SpeedButton1Click (Sender: TObject);
The begin
If (edit1. Text=' ') or (edit2. Text=' ') or (edit3. Text=' ') then
Showmessage (' Data is not enough! ')
The else
The begin
With adodataset1 do
The begin
Insert;
Fieldbyname (' building number '). AsString:=edit1. Text;
Fieldbyname (' building dish names.) AsString:=edit1. Text;
Post;
Refresh;
end;
end;

end;
It is ok,

CodePudding user response:

Positive solution, upstairs first open query result set, and then insert operation

CodePudding user response:

On a closed dataset can't perform the current operation, the cause of the data set did not open,

CodePudding user response:

Right, are generally do so

CodePudding user response:

refer to the second floor z1234abc response:
prompt like this place has a problem of fieldbyname (' building number). AsString:=edit1. Text;
Don't understand why

Modified into
Fieldbyname (' building number '). AsString:=trim (edit1. Text);

CodePudding user response:

Want to change, must first to adodataset. Edit, you must first set can edit can change him

CodePudding user response:

Error obviously, data sets, did not open, open the first line,
  • Related