BOOL CxxApp::StoreData(int nStartAddr, int nEndAddr)
{    RecordData *pRecordData = new RecordData;//存储数据的结构体
static int stnDataFiled = 0;
BOOL bResult = FALSE;     _variant_t var;
  ::CoInitialize(NULL);
_ConnectionPtr m_pConnection;
m_pConnection.CreateInstance(__uuidof(Connection));

try                 
{
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xxxx.mdb","","",adModeUnknown);
    
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败,确认数据库文件xxxx.mdb是否在当前路径下!");
return false;
}  
CString strData;
CString s_str[] = {"FIELD1","FIELD2","FIELD3","FIELD4","FIELD5",
"FIELD6","FIELD7","FIELD8","FIELD9","FIELD10",
"FIELD11","FIELD12","FIELD13","FIELD14","FIELD15",
"FIELD16"};
const int nfiledamount = sizeof(s_str)/sizeof(s_str[0]); _RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
 
try
{
m_pRecordset->Open(_variant_t("select * from REALDATA"),     m_pConnection.GetInterfacePtr(), adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}  
CString strTime;
CTime t = CTime::GetCurrentTime();
pRecordData->RecordTime = t;
strTime.Format("%d",t); //当数据库为空,就新建一行
 if(m_pRecordset->BOF&&m_pRecordset->adoEOF)
{
m_pRecordset->AddNew();
stnDataFiled = 0;
m_pRecordset->PutCollect("TIMEINDEX",_variant_t(strTime));
m_pRecordset->PutCollect("DATEINDEX",_variant_t(t.Format("%Y-%m-%d")));
} for(int nAddrIndex = nStartAddr; nAddrIndex <= nEndAddr; nAddrIndex++)
{
pRecordData->MeterAddress = nAddrIndex;
pRecordData->AlarmIndex = 0;//报警功能,暂时还没做,手置为0无报警
for(int nChannelIndex = 0;nChannelIndex < 4;nChannelIndex++)
{ if(m_nCurPV[nChannelIndex][nAddrIndex] != short(DEFAULT_VALUE)
&& m_nCurPV[nChannelIndex][nAddrIndex] != 0x7fff
&& m_nCurPV[nChannelIndex][nAddrIndex] != 0x7f00)
{
pRecordData->PresentValue = float(m_nCurPV[nChannelIndex][nAddrIndex])/(float)10.0;
pRecordData->ChannelCode = nChannelIndex + 1;

if(stnDataFiled >= nfiledamount)
{
m_pRecordset->AddNew();
stnDataFiled = 0;
m_pRecordset->PutCollect("TIMEINDEX",_variant_t(strTime));
m_pRecordset->PutCollect("DATEINDEX",_variant_t(t.Format("%Y-%m-%d")));

}
else
{

m_pRecordset->MoveLast();   <--------当写入第2次数据时候,这里出错 //判断是否是新的一天
CTime tOldtime;
var= m_pRecordset->GetCollect("TIMEINDEX");
tOldtime =var.intVal;
if(t.GetYear() != tOldtime.GetYear()
|| t.GetMonth() != tOldtime.GetMonth()
|| t.GetDay() != tOldtime.GetDay())
{
m_pRecordset->AddNew();
stnDataFiled = 0;
m_pRecordset->PutCollect("TIMEINDEX",_variant_t(strTime));
m_pRecordset->PutCollect("DATEINDEX",_variant_t(t.Format("%Y-%m-%d")));
}
}
// ds->MoveLast();

strData.Format("%d,%d,%d,%g,%d",
pRecordData->RecordTime,
pRecordData->MeterAddress,
pRecordData->ChannelCode,
pRecordData->PresentValue,
pRecordData->AlarmIndex); m_pRecordset->PutCollect(_variant_t(s_str[stnDataFiled]),_variant_t(strData));
// pRecordData++;
stnDataFiled++;
}
}
}
if(!(m_pRecordset->BOF && m_pRecordset->adoEOF))
{
m_pRecordset->Update();
}
delete pRecordData;
    m_pRecordset->Close();
m_pRecordset.Release();
m_pRecordset = NULL;

if(m_pConnection->State)
      m_pConnection->Close(); //关闭与数据库的连接
m_pConnection= NULL;  
bResult = TRUE; return bResult;}当指针第2次MOVELAST的时候,出错,请各位帮忙看下`