Reputation: 97
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery1.close;
ADOQuery1.SQL.text:='insert into veresiye (product,price,piece,total)
VALUES (:par0,:par1,:par2,:par3)';
ADOQuery1.Parameters.ParamByName('par0').Value:=Edit1.Text;
ADOQuery1.Parameters.ParamByName('par1').Value:=Edit2.Text;
ADOQuery1.Parameters.ParamByName('par2').Value:=Edit3.Text;
ADOQuery1.Parameters.ParamByName('par3').Value:=Edit4.Text;
ADOQuery1.Open;
ADOQuery1.ExecSQL;
end;
and I get this error message:
Adoquery1: CommandText does not return a result set
Why do I get this error and how can I fix it?
Upvotes: 2
Views: 11108
Reputation:
To insert values in table :
ADOQuery1.Close;
ADOQuery1.SQL.text:='insert into veresiye (product,price,piece,total)
VALUES (:par0,:par1,:par2,:par3)';
ADOQuery1.Parameters.ParamByName('par0').Value:=Edit1.Text;
ADOQuery1.Parameters.ParamByName('par1').Value:=Edit2.Text;
ADOQuery1.Parameters.ParamByName('par2').Value:=Edit3.Text;
ADOQuery1.Parameters.ParamByName('par3').Value:=Edit4.Text;
Try
ADOQuery1.ExecSQL;
except on E: Exception do
MessageDlg(E.Message,mtError,[mbOK],0);
End;
Upvotes: 1
Reputation: 2755
Call ExecSQL to execute the SQL statement currently assigned to the SQL property. Use ExecSQL to execute queries that do not return a cursor to data (such as INSERT, UPDATE, DELETE, and CREATE TABLE).
ExecSQL returns an integer value reflecting the number of rows affected by the executed SQL statement. Note: For SELECT statements, call Open instead of ExecSQL or set the Active property to true. To speed performance, an application should ordinarily prepare the query by setting the Prepared property to true before calling ExecSQL for the first time.
To insert values in table use :
ADOQuery1.close;
ADOQuery1.SQL.text:='insert into veresiye (product,price,piece,total)
VALUES (:par0,:par1,:par2,:par3)';
ADOQuery1.Parameters.ParamByName('par0').Value:=Edit1.Text;
ADOQuery1.Parameters.ParamByName('par1').Value:=Edit2.Text;
ADOQuery1.Parameters.ParamByName('par2').Value:=Edit3.Text;
ADOQuery1.Parameters.ParamByName('par3').Value:=Edit4.Text;
ADOQuery1.ExecSQL;
To get values from table use:
ADOQuery1.close;
ADOQuery1.SQL.text:='select * from veresiye';
ADOQuery1.Open;
Upvotes: 7
Reputation: 31393
You should simply remove the call to
ADOQuery1.Open;
Open
is used to open the dataset returned by the query. This is also equivalent to setting ADOQuery1.Active := true
. In this case, an INSERT
statement does not return a dataset so there is nothing to open.
ExecSQL
is used to execute statements that do not return a result dataset so that is all you need to use here.
Upvotes: 5