本帖最后由 zxzcad1 于 2010-01-26 17:08:55 编辑

解决方案 »

  1.   

    'delete from compal where Printdate='''+Datetostr(time1)+'''' 
      

  2.   

    'delete from compal where Printdate=#'+Datetostr(time1)+'#'
      

  3.   


    类型不匹配呀  Printdate是日期类型 qry1.SQL.Add('delete from compal where Printdate<'''+Datetostr(time1)+'''');error
      

  4.   

    temp:string;
    T:tdatetime;
    begin
      T:=incday(now,2);
      temp:=formatdatetime('yyyy-mm-dd',T);//如果楼主的数据库中的日期格式是这样的话,不是请修改引号中的格式;
      ......
      qry1.SQL.Add('delete from compal where Printdate <'+''''+temp'''');
      ....
    end;
      

  5.   

    temp:string;
    T:tdatetime;
    begin
      T:=incday(now,2);
      temp:=formatdatetime('yyyy-mm-dd',T);//如果楼主的数据库中的日期格式是这样的话,不是请修改引号中的格式;
      ......
      qry1.SQL.Add('delete from compal where Printdate <'+''''+temp+'''');
      ....
    end;
    上面的少了一个+号.......
      

  6.   

    temp:string;
    T:tdatetime;
    begin
      T:=incday(now,2);
      temp:=formatdatetime('yyyy-mm-dd HH:mm:ss',T);//如果楼主的数据库中的日期格式是这样的话,不是请修改引号中的格式;
      ......
      qry1.SQL.Add('delete from compal where Printdate <'+''''+temp+'''');
      ....
    end;
    这样试试,一般来说比较没有精确到秒的
      

  7.   


    哦 出现错误了 我跟踪下了SQL语句 发现好像不对哦 'select * from compal where Printdate <'2010-01-25 10:41:34''#$D#$A
    后面那块是什么
      

  8.   

      con1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+ExtractFilePath(Application.ExeName)+'data\record.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456';
      con1.Connected:=true;
      time1:=incday(now(),-2);
      temp:=formatdatetime('yyyy-mm-dd HH:mm:ss',time1);
      ShowMessage(temp);
      qry1.Active:=false;
      qry1.SQL.Clear;
      qry1.sql.Text:='select * from compal where Printdate <'+''''+temp+'''';
      qry1.Active:=True;
    select 也查询不起来
      

  9.   


    delete from compal where Printdate <'''+temp+''''
      

  10.   

    access的时间是要用#2009-1-1#这样的,不是'2009-1-1'
    还有可以用<%.10f 这种形式试试,就是datetime当浮点数算
      

  11.   

    你的那个错误是因为数据库中式日期时间性数据类型,而你的程序中使用的是字符型,所以会类型不匹配。但是这样的SQL语句在SQL_server中是没有问题的。在ACCESS中就会出现你说的错误。要是库的数据类型是你建立的话,建议改成文本型存储然后用第一种写法进行比较。
      

  12.   

    delete from compal where Printdate  <'+Datetostr(time);