第一步 :在头文件 stdafx.h文件中加入以下代码
#import "c:\program files\common files\system\ado\msado15.dll" rename_namespace("ADODB") rename("EOF", "ADOEOF")
using namespace ADODB;
第二步 在按钮控件下添加如下响应事件
void CDBGridDlg::OnBtnQuer()
{
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
m_pConnection.CreateInstance(_uuidof(Connection));
m_pRecordset.CreateInstance(_uuidof(Recordset));
m_pConnection->Open("DSN=dsn;pwd=lsqz;pwd=lsqz","","",0);
CString strSql="select * from cspcomnode";
BSTR bstrSQL = strSql.AllocSysString();
m_pRecordset->CursorLocation=adUseClient;
m_pRecordset->Open(bstrSQL,(IDispatch*)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
m_DBGrid.SetRefDataSource((LPUNKNOWN) m_pRecordset->GetDataSource());
return ;
}
第三步 编译
阅读(1732) | 评论(0) | 转发(0) |