视图中的一个问题:
BOOL  COdbcdemo2View::ShowInfomation(CString strSQL)
{
CRect rect;
CListCtrl& ctrlList=(CListCtrl&)GetListCtrl();
ctrlList.GetWindowRect(rect);

try{
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);
}
//读取记录信息
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;
}
void COdbcdemo2View::OnMenuitem32776() 
{
// TODO: Add your command handler code here
CListCtrl& ctrlList=(CListCtrl&)GetListCtrl();
ctrlList.DeleteAllItems();
while(ctrlList.DeleteColumn(0));
UpdateWindow(); CString strSQL;
strSQL=_T("SELECT * FROM rsb;");
if(!ShowInfomation(strSQL))   
MessageBox("数据获取失败!");
}
该程序可执行,但执行这里的时候
为什么会出现“0xec0.."指令所引用的内存“0003234”,该内存不能为read
请高手指教??

解决方案 »

  1.   

    m_pCommonRS什么时候打开的?
    m_pCommonRS->Open(CRecordset::dynaset,strSQL);
    CRecordset::dynaset改为缺省的试试
      

  2.   

    这段程序看起来没错,
    我感觉可能是你在其他的什么地方把m_pCommonRS或它的连接重置了
      

  3.   

    我单步调试时在
    if(m_pCommonRS->IsOpen())   m_pCommonRS->Close();
    这里出现Unhandled  exception in odbcdemo2.exe(MFC42D.DLL):0xc0000005:Access
    violation的错误,请问这是什么原因,我是菜鸟,请大师们说详细一点,不胜感激
      

  4.   

    m_pCommonRS在那定义的?都在那些方法(函数)中调用了?
      

  5.   

    应该是m_pCommonRS没有初始化
    在COdbcdemo2View的构造函数中加上m_pCommonRS=NULL;
    在COdbcdemo2View的InitialUpdate()函数中加上:CRecordset的派生类  m_pCommonRS=new  CRecordset的派生类;
      

  6.   

    m_pCommonRS定义为全局函数
    CCommonRS类是生成应用程序后新生成的类,由CRecordset类派生
    要怎么办啊
      

  7.   

    m_pCommonRS初始化了吗?
    如没做,象ms_wqs() 说的那样试试
    如还不行,把所有用到m_pCommonRS的地方找出来
      

  8.   

    同意楼上……检查地址,看看初始化了没………………upupup