如何使用datagrid
刚开始学使用datagrid,写了下面的代码:HRESULT hRet;
try {
hRet = m_connect.CreateInstance("ADODB.Connection");
if (SUCCEEDED(hRet))
{
hRet = m_connect->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=note.mdb", "", "", adModeUnknown);
}
}
catch (_com_error e) {
CString errormessage;
errormessage.Format("连接数据库失败!\r\n 错误信息:%s", (char*)e.Description());
AfxMessageBox(errormessage);
PostQuitMessage(1);
}
m_record.CreateInstance("ADODB.Recordset");
m_record->Open("SELECT * FROM test", _variant_t((IDispatch*)m_connect, true),adOpenStatic, adLockOptimistic, adCmdText);
m_dbGrid.SetCaption(_T("单击列头进行排序"));
m_dbGrid.SetRefDataSource((LPUNKNOWN)m_record);
// m_dbGrid.Refresh();
结果什么都没显示出来。。。为什么读不出数据呀??高手帮帮忙啊....