岁数大了,QQ也不闪了,微信也不响了,电话也不来了,但是图老师依旧坚持为大家推荐最精彩的内容,下面为大家精心准备的ado方式访问带密码数据库的方法,希望大家看完后能赶快学习起来。
【 tulaoshi.com - 编程语言 】
主要代码:
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,
adCmdText);
}
catch (_com_error &e)
{
sprintf(errMsg,_T("Code meaning = %s"), (char*) e.ErrorMessage());
AfxMessageBox(errMsg);
pRs-Close();
pConn-Close();
::CoUninitialize();
return;
}
try
{
while(!(pRs-EndOfFile))
{
CString pass = (LPCTSTR)(_bstr_t)pRs-GetCollect("pass");
if(pass.IsEmpty()) return;
SetDlgItemText(IDC_PASS,pass);
pRs-MoveNext();
//break;
}
pRs-Close();
pConn-Close();
}
catch (_com_error &e)
{
sprintf(errMsg,_T("Code meaning = %s"), (char*) e.ErrorMessage());
AfxMessageBox(errMsg);
pRs-Close();
pConn-Close();
::CoUninitialize();
return;
}
CoUninitialize();
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)来源:http://www.tulaoshi.com/n/20160219/1602560.html
看过《ado方式访问带密码数据库的方法》的人还看了以下文章 更多>>