用ado编程,想把指定记录集中的数据显示在datagrid中,不知道为什么datagrid中却显示不出任何记录,且只有两列空的记录,我的表里不止两个字段,但记录数一个不少,请各位多多指教!代码如下:char buf[100];
try
{
m_pSet = NULL;
m_pSet.CreateInstance("ADODB.Recordset");
sprintf(buf,"select * from swkr" );
m_pSet->CursorLocation = adUseClient;
m_pSet->Open(_variant_t(buf), _variant_t((IDispatch*)((CMaybeApp*)AfxGetApp())->m_pConnection,true),
adOpenStatic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
CDataGrid* pGrid = &m_DataGrid;
m_DataGrid.ShowWindow(SW_SHOW);
m_DataGrid.SetCaption(Name);
m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)(m_pSet));
m_DataGrid.Refresh();
UpdateData(FALSE);
try
{
m_pSet = NULL;
m_pSet.CreateInstance("ADODB.Recordset");
sprintf(buf,"select * from swkr" );
m_pSet->CursorLocation = adUseClient;
m_pSet->Open(_variant_t(buf), _variant_t((IDispatch*)((CMaybeApp*)AfxGetApp())->m_pConnection,true),
adOpenStatic,
adLockOptimistic,
adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
CDataGrid* pGrid = &m_DataGrid;
m_DataGrid.ShowWindow(SW_SHOW);
m_DataGrid.SetCaption(Name);
m_DataGrid.SetRefDataSource(NULL);
m_DataGrid.SetRefDataSource((LPUNKNOWN)(m_pSet));
m_DataGrid.Refresh();
UpdateData(FALSE);
该如何解决
m_ctlDataGrid.SetCaption(sTableLabel);
m_ctlDataGrid.SetRefDataSource(NULL);
m_ctlDataGrid.SetRefDataSource( (LPUNKNOWN) m_pRS );
m_ctlDataGrid.Refresh();
UpdateData(FALSE);