如:
  str:=Edit1.text;
  ADOQuery.close;
  ADOQuery.sql.clear;
  ADOQuery.sql.add('select * from customers where country=:str');
  ADOQuery.open;
就是从customers表中列出字段country等于Edit1内容
这样得不到我要的结果,如何改?

解决方案 »

  1.   

    这样可以:ADOQuery.sql.add('select * from customers where country='''+str+'''');
      

  2.   

    去掉str:=Edit1.text;改写如下:
      ADOQuery.sql.add('select * from customers where country=:str');
      ADOQuery.open;
      -->
      ADOQuery.sql.add('select * from customers where country=:str');
      ADOQuery1.Parameters.ParamByName('str').Value := Edit1.text;
      ADOQuery.open;
      

  3.   

    也可用楼上方法,会更好:
    ADOQuery.SQL.Text := 'select * from customers where country='+QuotedStr(str);
      

  4.   

    ADOQuery1.close;
    ADOQuery1.sql.clear;
    ADOQuery1.sql.add('select * from customers where country=:p1');
    ADOQuery1.Parameters.ParamByName('p1').Value := trim(Edit1.text);
    ADOQuery1.Open;