热情软件屋

 

为什么SQL使用变量不行


编号:QA004630
建立日期: 2002年6月3日 最后修改日期:2002年6月3日
所属类别:

孙秀刚:
    本人用 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;
    为什么?

回答:

    正确的语句为:
    ADOQuery1.sql.Add('select * from sys_user where usercode='''+code+'''');

此问题由李海回答。

附加关键字:编程, 源程序, programming, source code, Delphi, VCL, Borland, SQL查询, sql server, sql, query, select

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio