为什么SQL使用变量不行
编号:QA004630
建立日期: 2002年6月3日 最后修改日期:2002年6月3日
所属类别:
Q
孙秀刚:
本人用 DELPHI 5.0编写一个查询程序,其中有一条语句
ADOQuery1.sql.Add('select * from sys_user where usercode=''李二''');
其中'李三'应在程序中由用户输入 ,可以查询到?
但这样做就不行
var
code,pass:string;
begin
code:='sunxg';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.sql.Add('select * from sys_user where usercode=''+code+'‘');
edit1.text:=code;
ADOQuery1.open;
为什么?
A回答:
正确的语句为:
ADOQuery1.sql.Add('select * from sys_user where usercode='''+code+'''');
此问题由李海回答。
附加关键字:编程, 源程序, programming, source code, Delphi, VCL, Borland, SQL查询, sql server, sql, query, select。
| |
|
|
| |
|
|