ODBC使用时遇到的问题

yexll 2003-05-08 11:27:16
//我是初学,用ODBC调用数据库,使用的代码是
CListCtrl& ctrlList = (CListCtrl&) GetListCtrl();
ctrlList.DeleteAllItems();
while(ctrlList.DeleteColumn(0));
UpdateWindow();

CString strSQL;
strSQL = _T("SELECT * FROM saleinfo;");

if(!ShowInformation(strSQL)) AfxMessageBox("数据获取失败!");

//其中,showinformation的代码:
BOOL CXiaoshouView::ShowInformation(CString strSQL)
{
CRect rect;
CListCtrl& ctrlList = (CListCtrl&) GetListCtrl();
ctrlList.GetWindowRect(rect);

try{
// get recordset field information
BeginWaitCursor();
if(m_pCommonRS->IsOpen()) m_pCommonRS->Close();
m_pCommonRS->Open(CRecordset::dynaset, strSQL);
if(!m_pCommonRS->IsEOF()){
m_pCommonRS->MoveLast();
m_pCommonRS->MoveFirst();
}
int nFieldCount = m_pCommonRS->GetODBCFieldCount();
CODBCFieldInfo fieldinfo;
for(int n=0;n<nFieldCount;n++){
m_pCommonRS->GetODBCFieldInfo(n, fieldinfo);
int nWidth = ctrlList.GetStringWidth(fieldinfo.m_strName) + 15;
ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
}
// get recordset data information
CString strValue;
m_pCommonRS->MoveFirst();
int nCount = 0;

while(!m_pCommonRS->IsEOF()){
ctrlList.InsertItem(nCount, strValue);
for(int j=0;j<nFieldCount;j++){
m_pCommonRS->GetFieldValue(j, strValue);
ctrlList.SetItemText(nCount, j, strValue);
}
m_pCommonRS->MoveNext();
nCount ++;
}
EndWaitCursor();
}

catch(CDBException *e){
e->ReportError();
EndWaitCursor();
return FALSE;
}

return TRUE;
}


//但是编译的时候我只要点到这个地方,然后就会说
//"0x5f703ebf"指令引用的"0x00000004"内存,该内存不能为"read".
//要终止程序,请单击"确定".
//要调试程序,请单击"取消".

...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
mahatma_cn 2003-05-08
  • 打赏
  • 举报
回复
明显的访问违例。你自己找错误
yexll 2003-05-08
  • 打赏
  • 举报
回复
应该怎么办??请高手指教
yexll 2003-05-08
  • 打赏
  • 举报
回复
谢谢各位,正在寻找错误中....
leisureful 2003-05-08
  • 打赏
  • 举报
回复
看看是否是边界访问错误,如数据库为空已经到最后还MOVENEXT等等
yexll 2003-05-08
  • 打赏
  • 举报
回复
具体是哪个部分有错呢??
到底是SQL语句还是代码错了??
给个方向我好找/~谢谢了:)

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧