Home > Software engineering >  MFC ADO connection Access database queries
MFC ADO connection Access database queries

Time:04-27

Everybody, excuse me: under the MFC ADO connection Access database Open failure, prompt error is not specified, this is what causes?
The code is as follows:
In stdafx. H add
# import "c: \ program files \ common files \ system \ ado \ msado15 DLL" no_namespace rename (" EOF ", "adoEOF")

In CTestApp. CPP add
BOOL CTestApp: : InitInstance ()
{
AfxEnableControlContainer ();
if (! AfxOleInit ())
{
AfxMessageBox (L "OLE DLL failed to initialize");
Return FALSE;
}
}

In CTestDlg. H add
_ConnectionPtr m_pConnection;

In CTestDlg. CPP add
BOOL CTestDlg: : OnInitDialog ()
{
Retrieves the hr;
Try {
Hr=m_pConnection. CreateInstance (" ADODB. Connection ");
If (SUCCEEDED (hr))
{
Hr=m_pConnection - & gt; Open (" E: \ \ database \ \ test accdb ", ""," ", adModeUnknown);

}
}
Catch _com_error (e)
{
Cstrings errorMessage;
ErrorMessage. The Format (_T (" Connect db failed: % s "), e.E rrorMessage ());//hint here "unspecified error"
AfxMessageBox (errorMessage);
}
}

The above code, please give a bosses, give directions, what is wrong, why even open Access database will be an error? We should be grateful for your younger brother in this,
  • Related