+ -
当前位置:首页 → 问答吧 → 一个关于ado连接SQL的神秘的问题

一个关于ado连接SQL的神秘的问题

时间:2011-12-28

来源:互联网

while(!sql.pRecordset->adoEOF)
{
jb.lc->InsertItem(j++,L"");
if(VT_NULL != sql.pRecordset->GetCollect("信息标题").vt)
jb.lc->SetItemText(0,0,(CString)sql.pRecordset->GetCollect("信息标题"));
if(VT_NULL != sql.pRecordset->GetCollect("发送员工编号").vt)
jb.lc->SetItemText(0,1,(CString)sql.pRecordset->GetCollect("发送员工编号"));
if(VT_NULL != sql.pRecordset->GetCollect("接收员工编号").vt)
jb.lc->SetItemText(0,2,(CString)sql.pRecordset->GetCollect("接收员工编号"));
try{
if(VT_NULL != sql.pRecordset->GetCollect("消息编号").vt)
jb.lc->SetItemText(0,3,(_bstr_t)sql.pRecordset->GetCollect("消息编号"));
}
catch(_com_error& e)
{
AfxMessageBox(e.ErrorMessage(),MB_OK,0);
}

sql.pRecordset->MoveNext();
}


再try catch那段加完之前,都很正常,加上之后,就异常了,而且返回还显示是位置异常!如果去掉那段,在整个while循环里加try catch,则没有异常。

后来我反复调试,还发现一个问题,就算不加try catch那段,listcontrol只能显示第一行,下面几行虽然能被选中,但没有内容。

作者: ADOhaomafan   发布时间: 2011-12-28

while(!sql.pRecordset->adoEOF)
应为while(!sql.pRecordset->GetadoEOF())

作者: fight_in_dl   发布时间: 2011-12-28

此外,while循环前应调用sql.pRecordset->MoveFirst();
先将指针置于头部。

作者: fight_in_dl   发布时间: 2011-12-28