ADOQuery参数传递

  dbgrid1.DataSource := datasource1;
  datasource1.DataSet := adoquery1;
  Value := 1221;
  SQL := 'SELECT * FROM customer WHERE CustNo>:Number';
  adoquery1.SQL.Clear;
  adoquery1.Parameters.Clear;
  adoquery1.sql.Add(SQL);
//  adoquery1.ParamCheck := true;
  adoquery1.Parameters.ParamByName('Number').Value := strtointdef(edit1.Text, 1);

 

adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from new where 1=1');
adoquery1.SQL.Add('and 购货单位=:company');
adoquery1.SQL.Add('and 品名=:name');
adoquery1.Parameters[0].Value:=edit1.Text;
adoquery1.Parameters[1].value:=edit2.Text;
adoquery1.Open;
应该成



adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from new where 1=1');
adoquery1.SQL.Add('and 购货单位=:company');
adoquery1.SQL.Add('and 品名=:name');
adoquery1.Parameters.ParamValues['company']:=edit1.Text;
adoquery1.Parameters.ParamValues['name']:=edit2.Text;
adoquery1.Open;


adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from new where 1=1');
adoquery1.SQL.Add('and 购货单位=:company');
adoquery1.SQL.Add('and 品名=:name');
adoquery1.Parameters.ParamByName(''company').value:=edit1.text;
adoquery1.Parameters.ParamByName('name').value:=edit2.text;
adoquery1.Open;

http://www.delphibbs.com/keylife/iblog_show.asp?xid=22167

 

你可能感兴趣的:(query)