DM.ADODataSet1_bookyd.CommandType := cmdText; 了吗?

解决方案 »

  1.   

    DM.ADODataSet1_bookyd.Close();
       DM.ADODataSet1_bookyd.CommandText:='select * from bookyd';
       if(Ls<>'') then
          DM.ADODataSet1_bookyd.CommandText:=DM.ADODataSet1_bookyd.CommandText+' where '+Ls;//这儿不应该这样写,还没有open,所以就没有保存;
       DM.ADODataSet1_bookyd.Open();
      

  2.   

    请在SQL中用空格分隔关键字如:
    'select * from bookyd '+' where  ‘
    将Ls:=Ls+'writer like '+#39+'%'+edit2.Text+'%'+#39;改为
    Ls:=Ls+'writer like '+#39+'%'+trim(edit2.Text)+'%'+#39;
       
       
      

  3.   

    如果确定代码没有错误,请问你用的是哪一个版本的Delphi?打过ADO补丁了吗?
      

  4.   

    你用的是什么数据库,如果是SQL SERVER或是ACCESS
    把#39去掉试试
      

  5.   

    如果edit1.text='',而edit2.text<>''就会多出一个and.出错
      

  6.   

    看看我的代码吧!!!
    procedure TOloPersonForm.BitBtn2Click(Sender: TObject);
    var findrecord,tem:string;
    begin
          if trim(dxlookupedit1.Text)<>'' then
          begin
          tem:='fact_sname ='+''''+trim(dm.factory.fieldbyname('fact_sname').AsString )+'''';
          findrecord:=tem;
          end;
          if trim(dxlookupedit2.Text)<>'' then
          begin
          tem:='dept_name ='+''''+trim(dm.depart.fieldbyname('dept_name').AsString) +'''';
              if findrecord='' then
              findrecord:=tem
              else
              findrecord:=findrecord+' and '+tem;
          end;
          if trim(dxlookupedit3.Text)<>'' then
          begin
          tem:='grou_name ='+''''+trim(dm.Group1.fieldbyname('grou_name').AsString) +'''';
              if findrecord='' then
              findrecord:=tem
              else
              findrecord:=findrecord+' and '+tem;
          end;
          if trim(dxedit1.Text)<>'' then
          begin
          tem:='per_name ='+''''+trim(dxedit1.Text)+'''';
             if findrecord='' then
             findrecord:=tem
             else
             findrecord:=findrecord+' and '+tem;
          end;
          if trim(dxedit20.text)<>'' then
          begin
          tem:='per_coo ='+''''+'02250110'+trim(dxedit20.Text)+'''';
              if findrecord='' then
              findrecord:=tem
              else
              findrecord:=findrecord+' and '+tem;
           end;
    dm.VOldPerson.Filtered :=false;
    dm.VOldPerson.Filter:=findrecord;
    dm.VOldPerson.Filtered:=true;
    end;
      

  7.   

    基本上说来,是生成的动态sql有误,你可以跟踪一下,
    看看你生成的sql是否正确,这么长的程序,不高兴看,
    这种情况其实很容易解决,看看你生成的sql,把它放在专用的
    工具中执行,例如 sql server下,用 query analyzer,
    执行一下,就知道错在何处了
      

  8.   

    procedure TForm6.SpeedButton1Click(Sender: TObject);
    begin
        Ls:='';//已定义为string类型   if edit1.Text<>'' then
          Ls:='id like '+#39+'%'+edit1.Text+'%'+#39;   if edit2.Text<>'' then
       begin
          if (Ls<>'') then
             Ls:=Ls+' and ';
          Ls:=Ls+'writer like '+#39+'%'+edit2.Text+'%'+#39;
       end;   if edit3.Text<>'' then
       begin
          if(Ls<>'') then
             Ls:=Ls+' and ';
          Ls:=Ls+'bookname like '+#39+'%'+edit3.Text+'%'+#39;
       end;   if edit4.Text<>'' then
       begin
          if(Ls<>'') then
             Ls:=Ls+' and ';
         Ls:=Ls+'kind like '+#39+'%'+edit4.Text+'%'+#39;
       end;   if edit5.Text<>'' then
       begin
          if(Ls<>'') then
             Ls:=Ls+' and ';
          Ls:=Ls+'publish like '+#39+'%'+edit5.Text+'%'+#39;
       end;   DM.ADODataSet1_bookyd.Close();
    //加空格
       DM.ADODataSet1_bookyd.CommandText:='select * from bookyd ';
       if(Ls<>'') then
          DM.ADODataSet1_bookyd.CommandText:=DM.ADODataSet1_bookyd.CommandText+' where '+Ls;
       DM.ADODataSet1_bookyd.Open();end;
      

  9.   

    最好在DM.ADODataSet1_bookyd.Close();
    前加上一句showmessage(ls);看一个SQL语句的结果!!,不过看你的代码不是很严谨!hoho