cstring sql = select * from table;  //含有date类型
然后打开数据库表,没有问题
读各字段内容时
TheValue = m_pRecordset->Fields->GetItem("date类型的字段")->Value;
上面这个代码,如果“date类型的字段”有值则运行时会报错3147,
如果“date类型的字段”将有值的记录全删掉就能成功运行不报错。
请高手赐教!!!

解决方案 »

  1.   

    麻烦各位了,原来写添加数据库时
    CTime time
    time.foramt(%d-%m-%y); //问题就出在%y上
    应该用%Y 不然显示的是年份的后两位。
    写入数据库后变成了“01-10月-0082”,用上面代码访问字段就出错。
    不知道什么原因,解决了就好。 
      

  2.   

    _variant_t vnRCount= m_pRecordset>GetCollect("date类型的字段");m_db3.Format("%d-%d-%d %d:%d",((COleDateTime)vnRCount).GetYear(),((COleDateTime)vnRCount).GetMonth(),((COleDateTime)vnRCount).GetDay(),((COleDateTime)vnRCount).GetHour(),((COleDateTime)vnRCount).GetMinute());