procedure TForm1.Button2Click(Sender: TObject);
var
str:string;
begin
  str:=dbcombobox1.Text;
  with adoquery1 do
  begin
    connection:=adoconnection1;
     close;    SQL.Add('select * from rtu');
    sql.Add('where rtu_id=str');
    execsql;       //出错的地方  提示STR参数没有默认值
     open;
  end;

解决方案 »

  1.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
    str:string;
    begin
      str:=dbcombobox1.Text;
      with adoquery1 do
      begin
        connection:=adoconnection1;
         close;    SQL.Add('select * from rtu');
        sql.Add('where rtu_id='+quotedstr(str));
        //    execsql;       //出错的地方  提示STR参数没有默认值
        //上面的这行可以不用吧!!!因为下面有Open了。     open;
      end;
      

  2.   

    execsql;      
    open;
    这两条语句冲突。
      

  3.   

    execsql与 open的区别在于:execsql执行后不会返回数据集,而open返回数据集
      

  4.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
    str:string;
    begin
      str:=dbcombobox1.Text;
      with adoquery1 do
      begin
        close;
        connection:=adoconnection1;  //这里也要调整一下
        SQL.Add('select * from rtu');
        sql.Add('where rtu_id=str');
                                         //去掉 execsql;(execsql不返回数据集,active:=True;或open返回数据集)
        open;
      end;
      

  5.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
    str:string;
    begin
      str:=dbcombobox1.Text;
      with adoquery1 do
      begin
        close;
        connection:=adoconnection1;
        SQL.Add('select * from rtu ');//注意最后有个空格
        sql.Add('where rtu_id='+quotestr(str));
        open;
      end;
      

  6.   

    谢谢各位了,还有我选择一个值,在点击它为什么报错。语言错误,在查询表达式中RTU_ID=一个值,而在select * from rtu where rtu_id=另一个值
      

  7.   

    你的RTU_ID是什么类型呀??如果是字符型,必须加引号