如何在单文档的工程中显示数据库信息?
单文档的View由CListView类派生,可是显示不了字段名和字段的内容,执行时只显示了第一个字段的内容,如何解决?我显示的代码如下:
BOOL CDataBaseView::ShowInformation(CString strSQL)
{
CRect rect;
int iError = 0;
CListCtrl &ctrlList = (CListCtrl &) GetListCtrl();
ctrlList.GetWindowRect(rect);
try
{
BeginWaitCursor();
// 如果结果集已被打开,则关闭它
m_pCommonRS = new CCommonRs();
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;
iError = ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
if (iError == -1)
{
MessageBox("Error!");
}
}
// 读取记录信息
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;
}
BOOL CDataBaseView::ShowInformation(CString strSQL)
{
CRect rect;
int iError = 0;
CListCtrl &ctrlList = (CListCtrl &) GetListCtrl();
ctrlList.GetWindowRect(rect);
try
{
BeginWaitCursor();
// 如果结果集已被打开,则关闭它
m_pCommonRS = new CCommonRs();
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;
iError = ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
if (iError == -1)
{
MessageBox("Error!");
}
}
// 读取记录信息
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;
}
...全文
相关推荐
idea中database不显示问题的解决
主要介绍了idea中database不显示问题的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Oracle 数据库(Database, DB)
数据库基本概念 数据库(Database, DB) 数据库管理系统(Database Management System, DBMS) 数据库管理员( Database Administrator, DBA) 数据库系统( Database System, DBS ) 关系型数据库 E-R 模型(Entry-Relation)
如何在MFC单文档程序中实现全屏显示
这篇文档详细讲述了如何在MFC单文档程序中添加全屏显示的功能
单文档多视图显示
http://blog.csdn.net/usister/article/details/17613971 一个文档可能对应多个视图,同一份数据,可能需要多种方式来显示
基于单文档的MFC工程
包括两个部分: 1.程序视频讲解 2.源程序 学习visual studio 与vc++ 得经典入门资料


界面
