CEstimateDlg为我的主界面,里面包含一个list box,想要实现将数据表的内容显示在list box中,m_pSet为我从cdaorecordset继承来的csysdaorecordset类的对象,已连接至数据表,这一点没问题,数据表包含三项:m_ID,m_year,m_recp5_7,我的数据库是用的access97。每次运行程序,都会弹出一个对话框,说是某块内存不能为“read”,感觉这个错误提示好模糊,我只知道在读取数据表数据时的问题,但不知道如何解决,高手请帮我看一下,谢谢了! 
void CEstimateDlg::OnShow()   

    if(m_pSet.IsOpen()) 
    { 
m_pSet.Close(); 
    } 
    m_pSet.Open(); 
    m_pSet.MoveFirst();     this->count = 0; 
    CString  cs; 
    m_list.DeleteAllItems(); 
    
    while (!m_pSet.IsEOF()) 

 cs.Format("%s",m_pSet.m_ID); 
 m_list.InsertItem(count,cs,0); 
           m_list.SetItemText(count,0,cs);            cs.Format("%s",m_pSet.m_year); 
           m_list.SetItemText(count,1,cs); 
           cs.Format("%s",m_pSet.m_recp5_7);            m_list.SetItemText(count,2,cs); 
           m_pSet.MoveNext(); 
 count++; 
} } 

解决方案 »

  1.   

    if(m_pSet.IsOpen()) 
        { 
    m_pSet.Close(); 
        } 
        m_pSet.Open(); 关闭后,该m_pSet是一个无效的指针了,重新open出的问题
      

  2.   

    m_pSet.MoveFirst(); 应该是这句出问题吧...如果是bof或者是eof的情况能movefirst么...
      

  3.   

    谢谢两位对我问题的答复,不过我都试了,应该不是这两方面的问题to mfc168mscn上这样说的:
    CDaoRecordset::Close
    virtual void Close( );
    throw( CDaoException );ResClosing a CDaoRecordset object removes it from the collection of open recordsets in the associated database. Because Close does not destroy the CDaoRecordset object, you can reuse the object by calling Open on the same data source or a different data source.You can call Open again after calling Close. This lets you reuse the recordset object. to liuxiaoyi666我改为
    if((!m_pSet.ifEof())&&(!m_pSet.ifBof()))
    {
      m_pSet.MoveFirst();
      …………………………
      …………………………
    }
    之后还是不行
    我曾把while之后的语句注释掉,在while之前曾做过messagebox()提示,都可以显示,说明主要问题出在读数据表字段上,不因该是连接数据表的问题。
      

  4.   

    问问解决了,设置一个断点找出来了,取数据没问题,就是格式化时没注意没m_ID的类型