使用Delphi中的Ado组件访问Access数据库,sql语句是这么写的qrTempLocal.Close;
qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < :BeginDate and HadPrintFlag <> 0';
qrTempLocal.Parameters.ParamByName('BeginDate').Value := strEndTime - iTimeOut / (24 * 60);
qrTempLocal.ExecSQL;在执行ExecSQL的时候,报错“不正常的定义参数对象。提供了不一致或不完整的信息”然后将Sql语句改为如下形式:qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < #' + DatetimeToStr(strEndTime - iTimeOut / (24 * 60)) + '# and HadPrintFlag <> 0';在执行ExcelSQL时,仍然报告同样的错误,让我百思不得其解。

解决方案 »

  1.   


    BeginDate:=strEndTime - iTimeOut / (24 * 60));
    qrTempLocal.Close;
    qrTempLocal.SQL.Text := 'delete from printlist where (Lis_date < '+BeginDate+') and (HadPrintFlag <> 0)';
    qrTempLocal.ExecSQL;不过,不知道你BeginDate:=strEndTime - iTimeOut / (24 * 60));
    计算得到什么类型的值,我提供给你的是按照FLOAT或者INT类型处理
      

  2.   

    procedure TfrmMain.Timer1Timer(Sender: TObject);
    var
      EndTime: TDateTime;
    begin
      EndTime := Now;
      qrTempLocal.Close;
      qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < :BeginDate and HadPrintFlag <> 0';
        qrTempLocal.Parameters.ParamByName('BeginDate').Value := EndTime - 30 / (24 * 60);
      qrTempLocal.ExecSQL;
    end;
    上面是那个函数的简化版,它的作用是定时删除半小时之前的数据。
      

  3.   

    总共试了三种方式:
    1、
    qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < :BeginDate and HadPrintFlag <> 0';
    qrTempLocal.Parameters.ParamByName('BeginDate').Value := strEndTime - iTimeOut / (24 * 60);
    qrTempLocal.ExecSQL;
    2、
    qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < #' + DatetimeToStr(strEndTime - iTimeOut / (24 * 60)) + '# and HadPrintFlag <> 0';
    3、
    qrTempLocal.SQL.Text := 'delete from printlist where Lis_date < ''' + DatetimeToStr(strEndTime - iTimeOut / (24 * 60)) + ''' and HadPrintFlag <> 0';其中前两种方式报告同样的错误。第三种方式根本就语法不正确,因为是access数据库。