我用从CRecordset派生CMyRecordset,Access中的字段均被绑定,分别为
CString m_strName;
CTime   m_timeDate;     //在Access中为日期型,格式是短日期
CTime   m_timeTime;     //在Access中为日期型,格式是长时间
int     m_nRecordNum;   //序号
CMyDlg 中定义CMyRecordset m_Recordset;
添加记录函数实现
   if(m_Recordset.IsBof){
     nIdex=0;
   }
   else{
     m_Recordset.MoveLase();
     nIdex=m_Recordset.m_nRecordNum;
   }
   nIdex++;
   m_Recordset.AddNew();
   m_Recordset.m_strName="故障";
   m_Recordset.m_timeDate=CTime::GetCurrentTime();
   m_Recordset.m_timeTime=CTime::GetCurrentTime();
   m_Recordset.m_nRecordNum=nIdex;
   if(m_Recordset.CanUpdate()){
         m_Recordset.Update();    //调试是这步报错
   }
   当不是空表时,调试通过。空表情况,报错。
   错误信息:Unhandled exception in ShowAudio.exe(MFC42D.DLL):0xC0000005 Access Violation
   程序在此处停止
   _AFX_INLINE int CTime::GetYear() const
{ return (GetLocalTm(NULL)->tm_year) + 1900; }
   我想可能是向空表添加记录的原因。应该怎么加?

解决方案 »

  1.   

    总算有人来了,谢谢楼上的友情up。
    自己在up。
      

  2.   

    to jnxulei(石头) 我曾经碰到过类似问题,但忘记了如何解决的,问题好象是出在时间类型的字段上,你可以先将时间类型的字段赋成定值,一般可以解决。不错,每次都停在
    _AFX_INLINE int CTime::GetYear() const
    { return (GetLocalTm(NULL)->tm_year) + 1900; }
    这一句,应该是时间类型的问题。可是如果不是空表就不会出现这个问题。
    到底是什么原因呢?
      

  3.   

    SQL我属白痴级的,不会,帮你up。
    至于分数我想应该不是问题,我这个id有可用分3K多,需要的话可以借你。
      

  4.   

    问题我已经帮你解决了。
    在CMyRecordset类中,程序直接映射的变量是CTime类型的,进入CMyRecordset.h中将m_timeDate、m_timeTime的类型改为COLEDateTime类型,在你上述的程序中稍加改动:
       m_Recordset.m_timeDate=COLEDateTime::GetCurrentTime();
       m_Recordset.m_timeTime=COLEDateTime::GetCurrentTime();
    这样就可以了。
      

  5.   

    谢谢jnxulei(石头),问题解决。