如何向ADO组件的sql属性增添带有where条件变量的查询语句?(100分)

  • 主题发起人 主题发起人 Reagan
  • 开始时间 开始时间
R

Reagan

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样向ado控件中的sql属性书写大where条件变量的查询语句?
如:aql.add('select * from table1 where user=?变量')
 
aql.add('select * from table1 where user=:变量')
 
设变量:
var tmpname : string;
tmpNumb : integer;
aql.add('select * from table1 where user='''+tmpname+'''');//string
aql.add('select * from table1 where user='+inttostr(tmpNumb));//integer
 
aql.add('select * from table1 where user=:name')
adoquery1.parameters.parambyname('name').value:=edit1.text;
 
ADOQry.Close;
ADOQry.SQL.Clear ;

Sdate:=Form1.Cyear.Text+'-'+Form1.Cmon.Text+'-'+Form1.Cday.Text;
s:='Select line,standard,gloztl from TqcZtl Where riqi='+'''%s'''+' order by line ASC';
s:=Format(s,[Sdate]);

ADOQry.SQL.Add(s);
ADOQry.ExecSQL ;
ADOQry.Active:=true;
 
设变量:
var tmpname : string;
tmpNum : integer;
sql.text ;= 'select * from table1 where user = '+''''+tmpname+''''; //string
sql.text := 'select * from table1 where user = '+inttostr(tmpNum); //integer
 
aql.add('select * from table1 where user=:变量')
parameters.parambyname('变量').value := 实际值;
open;
 
ADOQry.Close;
ADOQry.SQL.Clear ;

设变量:
var tmpname : string;
tmpNum : integer;
sql.text ;= 'select * from table1 where user = '+''''+tmpname+''''; //string
sql.text := 'select * from table1 where user = '+inttostr(tmpNum); //integer
Sdate:=Form1.Cyear.Text+'-'+Form1.Cmon.Text+'-'+Form1.Cday.Text;
s:='Select line,standard,gloztl from TqcZtl Where riqi='+'''%s'''+' order by line ASC';
s:=Format(s,[Sdate]);

ADOQry.SQL.Add(s);
ADOQry.ExecSQL ;
ADOQry.Active:=true;
 
来晚了!
adodataset1.close;
adodataset1.commandtext:='select * from tablename where id=:id';
adodataset1.parameters.parambyname('id').value:=edit1.text;
adodataset1.open;
 
如果说是方便调试用变量的方法比较好
sqlstr:='select * from table where id>0 and ' + sqlstr;
//messagebox(0, pchar(sqlstr), 'test', mb_ok);
adoquery.sql.add(sqlstr);

如果说是方便写程序
adoquery.close;
adoquery.sql.clear;
adoquery.sql.add('select * from table where id>0 and company=:company');
adoquery.parameters.parambyname('company').value:=sqlstr;
adoquery.open;
 
楼上的都说了!
 
总结:向ADO组件的sql属性增添带有where条件变量的查询语句 之 大全
 
aql.add('select * from table1 where user=:name')
adoquery1.parameters.parambyname('name').value:=edit1.text;
我想應該是最簡單的方法了.
 
sql.add('select * from table1 where user='''+Edit.Text+'''');
应该是比较简单的了。
 
后退
顶部