DataGrid控件能够和数据库中的记录集进行绑定处理,修改 删除 更新等,
用法:
_RecordsetPtr _m
m_pRS = NULL;
m_pRS.CreateInstance( __uuidof(Recordset));
try
{
m_pRS->CursorLocation = adUseClient;
m_pRS->Open((LPCSTR)"select * from employee", (LPCSTR)pMainFrame->m_ptrConnection->GetConnectionString(), adOpenKeyset,adLockOptimistic, adCmdText);
}
catch (_com_error &e)
{
AfxMessageBox(GetErrorDescription(e));
}
//Demonstrates, how to populate DataGrid by assigning it a Recordset object.
m_ctlDataGrid.SetCaption(sTableName);
m_ctlDataGrid.SetRefDataSource(NULL);
m_ctlDataGrid.SetRefDataSource( (LPUNKNOWN) m_pRS );
m_ctlDataGrid.Refresh();
UpdateData(FALSE);
显示完成以后,数据库不能关闭,如果关闭后,数据则显示不出来