haci aliyev haci aliyev - 6 months ago 74
SQL Question

Adoquery1: CommandText does not return a result set

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?

Answer

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.

Source : http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/ADODB_TADOQuery_ExecSQL.html

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;
Comments