现在的位置: 首页 > 综合 > 正文

一个语法错误 ,但可通过编译 ///

2012年09月08日 ⁄ 综合 ⁄ 共 2010字 ⁄ 字号 评论关闭
一个语法错误 ,但可通过编译 /// Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061221151440186.html
大家好,刚学DElphi遇如下问题  
    用ADoConnection,ADOquery,Datasource   ,Dbgrid   连接了一个SQLserver数据库Store后  
  用Button来触发一个查询操作,       代码如下:  
  StoreAll   为数据库store中的表  
  Combobox1中的items为表StoreAll中的ProductName   ProductNum   字段  
  Combobox2中的items为〉,=   ,  
   
       
  procedure   TForm3.Button1Click(Sender:   TObject);  
  var  
      STRis:string;  
  begin  
      if(Combobox1.Text='')and(Combobox2.Text='')and(edit1.Text='')  
      then   showmessage('请选择查询条件')  
      else  
      begin  
          STRis:='select   *   from   StoreAll   where   '+Trim(combobox1.Text)+  
          trim(combobox2.Text)+''''+Trim(edit1.Text)+'''';  
          if   Combobox1.Text='ProductNum'   then  
                STRis:='select*   from   StoreAll   where'+Trim(combobox1.Text)+  
                Trim(Combobox2.Text)+Trim(Edit1.Text);  
          with   ADOquery1   do  
          begin  
              close;  
              SQL.Clear;  
              SQL.Add(STRis);  
              open;  
          end;  
      end;  
   
  end;  
   
  这些代码可以通过编译   但是运行时   出现   第一行:‘   ’运行时有语法错误   。  
   
  反复试很多边   也找不到错误   ,恳请各位高手指点。。  
 

procedure   TForm3.Button1Click(Sender:   TObject);  
  var  
      STRis:string;  
  begin  
      if(Combobox1.Text='')   or   (Combobox2.Text='')   or   (edit1.Text='')  
      begin  
          showmessage('请选择查询条件')  
          exit;  
      end;  
   
          STRis:='select   *   from   StoreAll   where       '+Trim(combobox1.Text)  
                        +trim(combobox2.Text)+Quotedstr(Trim(edit1.Text));  
          if   Combobox1.Text='ProductNum'   then  
                STRis:='select*   from   StoreAll   where     '+Trim(combobox1.Text)  
                              +Trim(Combobox2.Text)+Trim(Edit1.Text);  
          with   ADOquery1   do  
          begin  
              close;  
              SQL.Clear;  
              SQL.Add(STRis);  
              open;  
          end;  
      end;  
  end;

if(Combobox1.Text='')   or   (Combobox2.Text='')   or   (edit1.Text='')     then   //少了一个then   不好意思  
      begin  
          showmessage('请选择查询条件')  
          exit;  
      end;

 
  STRis:='select   *   from   StoreAll   where   '+Trim(combobox1.Text)+  
          trim(combobox2.Text)+''''+Trim(edit1.Text)+'''';  
  是否这些个‘Text’之间缺少连接字?如where   '   +   Trim(combobox1.Text)   +   '='   +   .......   and(or)   ......

这是SQL语句的问题,建议你通过F8来查看STRis值,或者把STRis显示出来看看SQL语法有无问题!在解决!

【上篇】
【下篇】

抱歉!评论已关闭.