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++;
} }
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++;
} }
解决方案 »
- windowless_richedit 插入图片的实现 了解的进!
- 请问在VC中如何设置,使打印机双面打印?
- 两个文本文件数据过滤?
- 多线程中用Mutex互斥访问资源的问题
- 郁闷,散分。出差兰州,钱包和手机被盗,寸步难行,郁闷!!!
- 不知道大家发现没有,最近登陆论坛很困难,总是说找不到服务器,我可在午夜以后试的,试了很多次才进来的,是不是论坛出了什么问题,应该
- 有关<<深入浅出MFC>>的问题
- 鼠标抓词的源代码
- win32 api 实现透明位图的问题
- 旧诗重提:用VC的ODBC访问数据库时,连接字符串中的端口号怎么设?
- VC能不能调用C#写的DLL呀?
- CSplitterWnd和CTabCtrl问题
{
m_pSet.Close();
}
m_pSet.Open(); 关闭后,该m_pSet是一个无效的指针了,重新open出的问题
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()提示,都可以显示,说明主要问题出在读数据表字段上,不因该是连接数据表的问题。