delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
简单问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061215102418294.html
var  
      strsql:string;  
      temp:string;  
   
      temp:=edt1.text;  
      strsql:='select   *   from   人事档案   where   部门='+''南京分公司\\''+temp';    
      qry1.close;  
      qry1.sql.clear;  
      qry1.sql.add(strsql);  
      qry1.open;  
   
  我的意思是执行一条sql   语句:  
            select   *   from   人事档案   where   部门='南京分公司\\temp'          
  老是报错,估计是逗号问题,怎么办?

strsql:='select   *   from   人事档案   where   部门='+''南京分公司\\''+temp';  
   
  不报错就希奇了  
   
  你这   南京分公司\\   和   temp   都是什么??

给你写好!  
  var  
      strsql:string;  
      temp:string;  
  begin  
      temp:=edt1.text;  
      strsql:='select   *   from   人事档案   where   部门=%s\\%s';    
       
      qry1.close;  
      qry1.sql.text:=format(strsql,['南京分公司',temp]);  
      qry1.open;  
  end;  
  搞定!

这样写即使正确也容易把人搞糊涂:  
  strsql   :=   'select   *   from   人事档案   where   部门='+''南京分公司\\''+temp';    
  我喜欢下面的写法:  
  strsql   :=   'select   *   from   人事档案   where   部门='   +   #39   +   '南京分公司\\'   +   temp   +   #39;    
   
 

strsql:='select   *   from   人事档案   where   部门='+'''南京分公司\\temp''';    
 

posted on 2009-05-12 16:03 delphi2007 阅读(124) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。