主要代码: CString strSql; TCHAR FileName[MAX_PATH],errMsg[MAX_PATH]; ::CoInitialize(NULL); //初始化Com IADORecordBinding *picRs = NULL; _RecordsetPtr pRs("ADODB.Recordset"); _ConnectionPtr pConn("ADODB.Connection" ); //CFootballTeamRs rsFootballTeam; GetModuleFileName(NULL,FileName,MAX_PATH); (_tcsrchr(FileName,'\\'))[1] = 0; lstrcat(FileName,_T("pass.mdb")); strSql = strSql + "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source = " + FileName + ";Persist Security Info=False;Jet OLEDB:Database Password=cd;"; //pConn->ConnectionString = chDataSource; //pConn->Provider = _T("Microsoft.Jet.OLEDB.4.0"); CString sqlSentence = _T("select * from pass"); try { pConn->Open((_bstr_t)strSql, "", "", adModeUnknown); pRs->QueryInterface( __uuidof(IADORecordBinding), (LPVOID*)&picRs); pRs->Open( (_variant_t)sqlSentence, // 查询DemoTable表中所有字段 pConn.GetInterfacePtr(), // 获取库接库的IDispatch指针 adOpenDynamic, adLockOptimistic, 希望看到更多更经典的开发技巧,请随时刷新《开发特区》栏目。 |
正在阅读:ado方式访问带密码数据库的方法ado方式访问带密码数据库的方法
2004-04-28 14:35
出处:CSDN
责任编辑:linjixiong
键盘也能翻页,试试“← →”键