一直使用的sql,因为access方便,使用access2003做数据库,发现再插入时间时出现问题insert into a (date)values('''+formatdatetime('yyyy-mm-dd',datetimepicker1.date)+''')总是报错,大致为‘标准表达式中数据类型不匹配’,
access中该字段设置的  日期/时间 类型,求解

解决方案 »

  1.   

    formatdatetime 返回的是字符串//这样试试
    insert into a (date)values('+formatdatetime('yyyy-mm-dd',datetimepicker1.date)+')
      

  2.   

    关键是后来我需要针对事件处理部分
    比如1.XX时间到XX时间的数据统计
        2.单独获取时间中的月份,按月来统计数据 等等  文本格式转时间应该更麻烦了吧
      

  3.   

    insert into a (date) values(DateValue('''+formatdatetime('yyyy-mm-dd',datetimepicker1.date)+'''))
    DateValue()是VBA函数
      

  4.   

    这是你使用的数据库,字段的格式不兼容造成的。Date字段,它包含Date和Time两个值。所以,我在使用数据库时,不使用DATE字段,直接使用字符字段。这样,读取数据和写入数据时,都要进行转换。但无格式兼容问题。
      

  5.   

      qry1.SQL.Text := 'insert into a(date) values(:DT)';
      qry1.Parameters.ParamByName('DT').Value := now;
      qry1.ExecSQL;