while (!m_adoDataSet.IsEof())
{
m_adoDataSet.GetFieldValue("teneID",teneIDStr);
sql2 = "select max(ID) from data where teneID='";
sql2 += teneIDStr + "'";
if (pRst3->State)
{
pRst3->Close();
}
pRst3->Open(sql2.AllocSysString(),_variant_t((IDispatch*)(m_pDBCon->GetActiveConnection()),true),adOpenStatic,adLockOptimistic,adCmdText);

VdataID = pRst3->GetCollect("max(ID)");

//dataIDInt = VdataID.intVal;
      VdataID.ChangeType(VT_BSTR,NULL);
dataIDStr = VdataID.bstrVal;

sql = "select data.roomTemp,data.hotVal,data.nowTime,data.state,relation.roomID,room.roomAre from data,room,relation where relation.floorID='";
sql += str + "' and room.roomID=relation.roomID and data.teneID=relation.teneID and data.ID='";
sql += dataIDStr + "'";
/*if (pRst->State)
{
pRst->Close();
}*/

pRst->Open(sql.AllocSysString(),_variant_t((IDispatch*)(m_pDBCon->GetActiveConnection()),true),adOpenStatic,adLockOptimistic,adCmdText);

m_adoDataSet.MoveNext();

}
m_ctrlDG.SetRefDataSource(NULL);
m_ctrlDG.SetRefDataSource(pRst);
m_ctrlDG.Refresh();
为什么pRst我不关闭,程序就崩溃,但是关闭后,m_ctrLDG显示的数据就只有最后一条,而且还显示了两遍,我该怎么去处理???