关闭Recordset出错
if (dlg.DoModal()==IDOK) {
m_pConnection->Open("","","",adConnectUnspecified);
m_pCommand->put_ActiveConnection(_variant_t((IDispatch*)m_pConnection));
m_pCommand->CommandText=(char*)_bstr_t("insert into phonebook (name,phone) values ('"+dlg.m_name+"','"+dlg.m_phone+"')");
m_pRecordset=m_pCommand->Execute(NULL,NULL,adCmdText);
m_pRecordset->Close(); //这儿runtime error
m_pConnection->Close();
}
太奇怪了,上面是add按钮的代码,下面是CDialog::OnInitDialog的代码,没错
m_pCommand->CommandText="select * from phonebook";
m_pRecordset=m_pCommand->Execute(NULL,NULL,adCmdText);
m_pRecordset->MoveFirst();
while (!m_pRecordset->adoEOF) {
CString s;
s=(char*)(_bstr_t(m_pRecordset->GetCollect("name"))+"\t\t"+_bstr_t(m_pRecordset->GetCollect("phone")));
m_phonelist.AddString(s);
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_pConnection->Close();