bool CAdoRWAccess::ModifyData(int p_id,CString p_news,CString p_newsData,CString p_newsTime) 
{
CString strSql;
strSql.Format("SELECT * FROM news WHERE ID = %d",p_id);
if(QueryAccess(strSql)==TRUE)
{
// 修改当前记录的字段值
try
{
//得到现在的时间
SYSTEMTIME  curTime;
GetLocalTime( &curTime );
int y=curTime.wYear;
int m=curTime.wMonth ;
int d=curTime.wDay ;
NowTime.Format("%d-%02d-%02d",y,m,d);  m_pRecordset->PutCollect("news", _variant_t(p_news));  //出错了,为什么???
m_pRecordset->PutCollect("newsData", _variant_t(p_newsData));
m_pRecordset->PutCollect("newsTime",_variant_t(p_newsTime));
m_pRecordset->Update();
return true;
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return false;
} }
return false;
}其中字段 news newsData  是 备注类型    
newsTime 是时间日期类型
我用的是ACCESS数据库
请问,为什么不能修改???
时间备注类型在vc中怎么转换??:)

解决方案 »

  1.   

    你怎么没有写
    m_pRecordSet->AddNew();
    备注字段如果不很长,可以用CString型,长的话,需要用char*
      

  2.   

    在access中,时间要用##括起来,备注不用转换
      

  3.   

    修改字段值时需要将指针移到正确的位置上,如果指针位置不正确就会出错,如这时的m_pRecordSet->IsBOF或m_pRecordSet->IsEof如果为True,就要用m_pRecordSet->MoveFirst()或其它方法移动。
      

  4.   

    是编译出错还是运行出错?你不用变量p_news,直接写字符串试试看。。更新日期型字段用下面的方法:
    COleDateTime oletime(2004, 12, 15, 00, 00, 02);m_pRs->PutCollect("ID",_variant_t("01"));
    m_pRs->PutCollect("NAME",_variant_t("tabby"));
    m_pRs->PutCollect("PASSWORD",_variant_t("tabby01"));
    m_pRs->PutCollect("JOINTIME",_variant_t(oletime));
    m_pRs->Update();