OnDel() 时 调用OnRead()时就会出现IDispatch error #3107错误,应该怎么改?void CAdoInstanceDlg::OnDel()
{
CString strSql="select * from UserInfo";
BSTR bstrSQL = strSql.AllocSysString();
try{ m_pRec->MoveFirst(); m_pRec->Delete(adAffectCurrent);
}catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
OnRead();}
void CAdoInstanceDlg::OnRead()
{int iIndex=0;
try
{ CString strSql="select * from UserInfo";
BSTR bstrSQL = strSql.AllocSysString();
try{ m_pRec->Open(bstrSQL,(IDispatch*) m_pCon,adOpenDynamic,adLockOptimistic,adCmdText);
m_pRec->MoveFirst();
del=true;
}catch(_com_error e){del=false;}
if(del)
{
m_list.DeleteAllItems();
} while(!m_pRec->adoEOF)//遍历所有记录
{
_variant_t UserID,UserName;
UserID = m_pRec->GetCollect("UserID");
UserName = m_pRec->GetCollect("UserName");
if(UserID.vt!=VT_NULL && UserName.vt!=VT_NULL) {
m_list.InsertItem(iIndex,(char*)_bstr_t(UserID));
m_list.SetItemText(iIndex,1,(char *)_bstr_t(UserName));
iIndex++; }
m_pRec->MoveNext();
}
}catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage()); }
}
{
CString strSql="select * from UserInfo";
BSTR bstrSQL = strSql.AllocSysString();
try{ m_pRec->MoveFirst(); m_pRec->Delete(adAffectCurrent);
}catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
OnRead();}
void CAdoInstanceDlg::OnRead()
{int iIndex=0;
try
{ CString strSql="select * from UserInfo";
BSTR bstrSQL = strSql.AllocSysString();
try{ m_pRec->Open(bstrSQL,(IDispatch*) m_pCon,adOpenDynamic,adLockOptimistic,adCmdText);
m_pRec->MoveFirst();
del=true;
}catch(_com_error e){del=false;}
if(del)
{
m_list.DeleteAllItems();
} while(!m_pRec->adoEOF)//遍历所有记录
{
_variant_t UserID,UserName;
UserID = m_pRec->GetCollect("UserID");
UserName = m_pRec->GetCollect("UserName");
if(UserID.vt!=VT_NULL && UserName.vt!=VT_NULL) {
m_list.InsertItem(iIndex,(char*)_bstr_t(UserID));
m_list.SetItemText(iIndex,1,(char *)_bstr_t(UserName));
iIndex++; }
m_pRec->MoveNext();
}
}catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage()); }
}
解决方案 »
- ado打包后不刷新,导致datagrid数据不能更新
- 新建子对话框没有事件响应×××××××××
- "."和".."分别代表什么
- 急问!!怎样实现菜单项的动态装入!?高分在线等!!
- 新手请教:先LeaveCriticalSection再EnterCriticalSection,这样会有什么后果?
- ***超级难题: 将BYTE flag[8]; 这个变量的任意一位置0/1, 怎么编写这个函数? ***
- 真是郁闷啊 read()vs write()!!!
- 关于开发数据库程序的讨论(欢迎发言)
- VC开发数据库有什么优势啊?
- 关于ftp编程问题???
- VC程序启动顺序?
- 简单问题,修改Menu文字后,Menu不响应消息
http://www.codeproject.com/database/mssqltutorial.asp
m_pRec->MoveFirst();
m_pRec->Delete(adAffectCurrent);
} //这里的m_pRec是如何Open的?
http://www.qhtx.net/web/CSDN/asppost11/web229154.htm
这个帖子~~~
支持楼上的办法,强烈支持
把m_pRec->Open(......)放在OnInitDialog()里就好了……
这么说m_pRec->Open(......)不能重复执行?