视图中的一个问题:
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
请高手指教??
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
请高手指教??
解决方案 »
- 有知道这个RpcTryExcept 与RpcExcept搭配使用是干什么的吗?
- Hook CopyFile()的问题,得不到我想要的效果
- 为什么编译会出现:系统找不到指定的路径,Error executing c:\winnt\system32\cmd.exe
- 如何让ListCtrl控件显示在文档视图结构中。
- 关天链表的问题
- 局域网中,如何编程实现共享目录?
- 【还我硬盘空间呀】 问题是:::不允许格式化系统分区
- SDK 绘图
- 为什么ShowWindow对最小化的窗口无效呢?(一个主窗口上有几个子窗口,相互可以切换窗口界面,当程序最小化后,通过代码设置计时器来切换界面,发现无效)
- 请问怎样把硬盘的驱动器的盘符(包括软驱,光驱)加入组合框中。(一定给分)
- 怎么样增加上下文相关帮助
- 关于如何使用这个RegCreateKeyEx函数????
m_pCommonRS->Open(CRecordset::dynaset,strSQL);
CRecordset::dynaset改为缺省的试试
我感觉可能是你在其他的什么地方把m_pCommonRS或它的连接重置了
if(m_pCommonRS->IsOpen()) m_pCommonRS->Close();
这里出现Unhandled exception in odbcdemo2.exe(MFC42D.DLL):0xc0000005:Access
violation的错误,请问这是什么原因,我是菜鸟,请大师们说详细一点,不胜感激
在COdbcdemo2View的构造函数中加上m_pCommonRS=NULL;
在COdbcdemo2View的InitialUpdate()函数中加上:CRecordset的派生类 m_pCommonRS=new CRecordset的派生类;
CCommonRS类是生成应用程序后新生成的类,由CRecordset类派生
要怎么办啊
如没做,象ms_wqs() 说的那样试试
如还不行,把所有用到m_pCommonRS的地方找出来