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".
//要终止程序,请单击"确定".
//要调试程序,请单击"取消".