procedure TForm1.Button1Click(Sender: TObject);
var
pno,pname:string;
begin
   self.ADOQuery1.Close;
   pno:= edit1.Text;
   pname:= edit2.Text;
   self.ADOQuery1.SQL.Clear;
   self.ADOQuery1.SQL.Add('Insert into b (id,name) values(pno,pname)');
   self.ADOQuery1.Open;
end;
编译通过,运行错误
错误提示:在此上下文中不允许使用PNO,此处只允许使用变量,表达式或常量,
不允许使用列名
请问要怎样修改

解决方案 »

  1.   

    试试直接用
    self.ADOQuery1.SQL.Add('Insert into b (id,name) values(edit1.text,edit2.text)');
    huo  pname)');
      

  2.   

    如果
    id是整形
    name是字符串
    self.ADOQuery1.SQL.Add('Insert into b (id,name) values('+pno+','+''''+pname+''''+')');
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    pno,pname:string;
    begin
       self.ADOQuery1.Close;
       pno:= edit1.Text;
       pname:= edit2.Text;
       self.ADOQuery1.SQL.Clear;
       self.ADOQuery1.SQL.Add('Insert into b (id,name) values('''' + pno + ''',' + '''' + pname+'''')');
       self.ADOQuery1.Open;
    end;
      

  4.   

    不好意思,错了一行。
     self.ADOQuery1.SQL.Add('Insert into b (id,name) values('''' + pno + ''',' + '''' + pname+''')');
      

  5.   

    注意,没有返回数据集的时候,应该用ADOQuery1.ExecSQL;
      

  6.   

    在adoquery的属性sql中写出带参数的sql语句
    程序中写 adoquery1.params.paramvalue['id;name']:=
        vararrayof([edit1.text,edit2.text]);
      

  7.   

    在adoquery的属性sql中写出带参数的sql语句
      self.ADOQuery1.SQL.Add('Insert into b (id,name) values(:id,:name)');
      

  8.   

    self.ADOQuery1.SQL.Add('Insert into b (id,name) values(:id,:name)');
    adoquery1.params.paramvalue['id;name']:=vararrayof([edit1.text,edit2.text]);
      

  9.   

    把这行改掉
     self.ADOQuery1.SQL.Add('Insert into b (id,name) values
    (pno,pname)');
    self.ADOQuery1.SQL.Add('Insert into b (id,name) values('''' + pno + ''',' + '''' + pname+''')');