如何在单文档的工程中显示数据库信息?

CoomyMorris 2005-08-26 08:53:23
单文档的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;
}
...全文
76 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wshcdr 2005-08-26
  • 打赏
  • 举报
回复
ctrlList.InsertColumn(

确定这个是加Column?
Kudeet 2005-08-26
  • 打赏
  • 举报
回复
LONG lStyle;
lStyle=GetWindowLong(ctrlList.GetSafeHwnd(),GWL_STYLE);//获取当前窗口类型
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle|=LVS_REPORT; //设置显示方式为report方式
SetWindowLong(ctrlList.GetSafeHwnd(),GWL_STYLE,lStyle);//设置窗口类型
CoomyMorris 2005-08-26
  • 打赏
  • 举报
回复
ctrlList.InsertColumn(n, fieldinfo.m_strName, LVCFMT_LEFT, nWidth);
这句执行没有效果,怎么回事?

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧