表字段为id1,id2,htime
ACCESS数据库,htime字段选择为  日期/时间 sqlstr:=Format('insert into TINPUTGOODS values(%d,%d,''%s'')',
                [1,20,datetimetostr(now)]);  以上语句以SQL Server后台数据库执行没问题
  但是ACCESS数据执行时 日期/时间 字段出错。因为ACCESS执行下面是对的:
sqlstr:=Format('insert into TINPUTGOODS(id1,id2) values(%d,%d)',
                [1,20]);大家可以试试!

解决方案 »

  1.   

    function TCustomAppInfo.GetDbTimeString(dt: TDateTime): String;
    begin
      case DBType of
        dtOracle:
          Result:='To_Date('''+FormatDateTime('yyyy-mm-dd hh:nn:ss',dt)+''',''YYYY-MM-DD HH24-MI-SS'')';
        dtMsSql:
          Result:='CONVERT(DATETIME,'''+FormatDateTime('yyyy-mm-dd hh:nn:ss',dt)+''',20)';
        dtJet40:
          Result:='CDate('''+FormatDateTime('mm/dd/yyyy hh:nn:ss',dt)+''')';
      end;
    end;
      

  2.   

    sqlstr:=
    'insert into TINPUTGOODS values(1,20,"' + datetimetostr(now()) + '")'
      

  3.   

    象你那样写当然不行了
    每种数据库都有自己的函数,而且都不一样,你可以参考上边的函数,是适应Oracle,MsSql,ACCESS三种类型的数据库的strSql:='insert into tablename (f1) values ('+GetDbTimeString(now)+')';
      

  4.   

    access 中查询的日期可以用 #2002-1-1# 表示
      

  5.   

    是用select * from table where date=#2002-1-1#
      

  6.   

    xht:这样就可以了,我刚刚试过。
    procedure TForm1.FormDblClick(Sender: TObject);
    var
      tm:string;
      tDay,tMonth,tYear:word;
    begin
      adoquery1.SQL.Clear;
      DecodeDate(now,tYear,tMonth,tDay);
      tm:='insert into TINPUTGOODS values(1,20,'+''''+IntToStr(tMonth)+'-'+IntToStr(tDay)+'-'+IntToStr(tYear)+''''+')';
      adoquery1.SQL.Add(tm);
      adoquery1.ExecSQL;
    end;
      

  7.   

    真拿你每办法,一点脑子都不动啊
    好了,写给你直接就能用的
    ACCESS:
    strSql:='insert into TINPUTGOODS values(1,20,CDate('''+FormatDateTime('mm/dd/yyyy hh:nn:ss',now)+'''))';
    MsSql:
    strSql:='insert into TINPUTGOODS values(1,20,CONVERT(DATETIME,'''+FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+''',20))'
    Oracle:
    strSql:='insert into TINPUTGOODS values(1,20,To_Date('''+FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+''',''YYYY-MM-DD HH24-MI-SS''))'