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只能显示第一行,下面几行虽然能被选中,但没有内容。
{
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只能显示第一行,下面几行虽然能被选中,但没有内容。
应为while(!sql.pRecordset->GetadoEOF())
先将指针置于头部。
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);
}别的问题都解决了,就是这段代码的问题没有解决!!!!!!这是怎么回事哇?????????
改为
jb.lc->SetItemText(j,3,(_bstr_t)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);
}
这段代码,那么一切正常。
但是加了这段代码后,就异常了,求解!!!!
在程序里同样的nchar我都用CString保存的,都没有问题,而且有一次我没用CString结果异常,e显示的是不正确的数据类型。我都换过一个msado.dll了……两个dll一个500+k一个300+,到这儿都异常!!
气死我了~~~~
if(VT_NULL != sql.pRecordset->GetCollect("消息编号").vt)
vValue=sql.pRecordset->GetCollect("消息编号");
if(vValue.vt !=VT_NULL)
CString strTmp;
var = sql.pRecordset->GetCollect(_variant_t((long)ColNO)); //ColNO为“消息编号”的列编号
if(VT_NULL == var.vt)
{
strTmp = var;
jb.lc->SetItemText(j,3,strTmp);
}
if(VT_NULL != var.vt)我怀疑出错的地方是SetItemText
先用CString赋值一下