MFC 利用ADO连接ACCESS数据库失败 怎么回事呀
3个回答
展开全部
先导入ado库
#pragma warning(disable:4146)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","ENDOFFILE")
BOOL CADODlg::GetData()
{
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_bstr_t Connection="Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=H:\\LoginDemo.mdb;Persist Security Info=FALSE";
pConn->Open(Connection,"","",adConnectUnspecified);
_RecordsetPtr pRs("ADODB.Recordset");
CString strSQL;
strSQL.Format("select * from USERINFO");
pRs->Open(_variant_t(strSQL.GetBuffer(strSQL.GetLength())),_variant_t(pConn,true),adOpenStatic,
adLockOptimistic,adCmdText);
if(pRs->BOF)
{
pRs->Close();
pRs.Release();
pConn->Close();
pConn.Release();
return FALSE;
}
else
{
strcpy(m_username.GetBuffer(255),_bstr_t(pRs->GetCollect("USERNAME")));
strcpy(m_password.GetBuffer(255),_bstr_t(pRs->GetCollect("PASSWORD")));
UpdateData(FALSE);
pRs->Close();
pRs.Release();
pConn->Close();
pConn.Release();
return TRUE;
}
}
catch(_com_error &e)
{
CoUninitialize();
::AfxMessageBox(e.ErrorMessage());
return FALSE;
}
}
#pragma warning(disable:4146)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","ENDOFFILE")
BOOL CADODlg::GetData()
{
CoInitialize(NULL);
try
{
_ConnectionPtr pConn("ADODB.Connection");
_bstr_t Connection="Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=H:\\LoginDemo.mdb;Persist Security Info=FALSE";
pConn->Open(Connection,"","",adConnectUnspecified);
_RecordsetPtr pRs("ADODB.Recordset");
CString strSQL;
strSQL.Format("select * from USERINFO");
pRs->Open(_variant_t(strSQL.GetBuffer(strSQL.GetLength())),_variant_t(pConn,true),adOpenStatic,
adLockOptimistic,adCmdText);
if(pRs->BOF)
{
pRs->Close();
pRs.Release();
pConn->Close();
pConn.Release();
return FALSE;
}
else
{
strcpy(m_username.GetBuffer(255),_bstr_t(pRs->GetCollect("USERNAME")));
strcpy(m_password.GetBuffer(255),_bstr_t(pRs->GetCollect("PASSWORD")));
UpdateData(FALSE);
pRs->Close();
pRs.Release();
pConn->Close();
pConn.Release();
return TRUE;
}
}
catch(_com_error &e)
{
CoUninitialize();
::AfxMessageBox(e.ErrorMessage());
return FALSE;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询