标题:datagrid控件不能正常显示记录集,紧急求助
只看楼主
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
结帖率:33.33%
 问题点数:0 回复次数:0 
datagrid控件不能正常显示记录集,紧急求助
datagrid控件不能正常显示记录集

BOOL ShowGrade::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
//_ConnectionPtr m_ADOCon;
//_RecordsetPtr m_pSet;
m_ADOCon.CreateInstance(__uuidof( Connection));
try
{
m_pSet.CreateInstance (__uuidof(Recordset));
}
catch (_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
_variant_t RecordsAffected;
HRESULT hr;
try
{
hr=m_ADOCon->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb",
"","",
adModeUnknown);
if (SUCCEEDED(hr))
{
//rs.CursorLocation = adUseClient
m_pSet->CursorLocation=adUseClient;
hr=m_pSet->Open("SELECT * FROM grade",m_ADOCon.GetInterfacePtr(),
//adOpenDynamic,
adOpenStatic,
adLockOptimistic,
adCmdUnknown);

//=m_ADOCon->Execute("",&RecordsAffected,adCmdText);
if(!SUCCEEDED(hr))
AfxMessageBox("Open set error");
}
else
AfxMessageBox("Open database error");
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("记录集创建失败\r\n 错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
////////
//test for m_pSet is succeeded;
//_variant_t var;
//var =m_pSet->GetCollect("序号");
//AfxMessageBox((LPCSTR)_bstr_t(var));


//////
m_ctrlDG.SetCaption(_T("数据库表内容"));
//m_ctrlDG.SetRefDataSource((LPUNKNOWN)m_pSet);
m_ctrlDG.SetRefDataSource(NULL);
m_ctrlDG.SetRefDataSource((LPUNKNOWN)m_pSet);
m_ctrlDG.Refresh();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
DataGrid 控件中,只显示多个空行,没有数据,有高手说是记录集的问题,不知怎么解决呀

搜索更多相关主题的帖子: style 记录 
2006-10-17 16:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-96922-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.333413 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved