简单问题 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''';    
 

相关文章:

  • 2021-06-09
  • 2022-12-23
  • 2021-08-31
  • 2021-06-14
  • 2021-05-20
  • 2022-01-04
  • 2021-06-13
  • 2022-02-25
猜你喜欢
  • 2021-09-19
  • 2021-12-19
  • 2022-12-23
  • 2021-06-25
  • 2021-08-31
  • 2021-09-21
  • 2021-11-25
相关资源
相似解决方案