ado抛出异常

来源:百度知道 编辑:UC知道 时间:2024/05/24 22:38:12
//创建并打开数据库连接对象
_variant_t vFieldValue;
CString strFieldValue;
int i=0;
try
{
if(!LoadDbSource("chaoshiguanli","D:\\重要资料\\毕业设计\\超市管理系统.mdb","超市管理系统数据源"))
{
EndDialog(0);
//return FALSE;
}
if(::CoInitialize(NULL))
{
//AfxMessageBox("初始化环境成功!");
}
m_pCon.CreateInstance(__uuidof(Connection));
if(m_pCon->Open("chaoshiguanli","","",NULL))
{
AfxMessageBox("打开数据库成功!!");
}

//创建并打开记录集对象
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs->Open("select * from 人事管理",m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
m_pRs->AddNew();
m_pRs->PutCollect("编号",_variant_t(m_Rsbianhao));
m_pRs->PutCollect("姓名",_variant_t(m_Rsxingming));
m_pRs->PutCollect("

按照以下方法可看到具体哪里出错了,当然也可以用F10单步调试

catch(_com_error e)
{
CString strComError;
strComError.Format("错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(), // 错误编号
e.ErrorMessage(), // 错误信息
(LPCSTR) e.Source(), // 错误源
(LPCSTR) e.Description()); // 错误描述
MessageBox(strComError,"错误");
}