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

一个语法错误 ,但可通过编译 /// 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语法有无问题!在解决!

转载于:https://www.cnblogs.com/delphi2007/archive/2008/12/11/1352519.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值