Currently, ado technology has become the mainstream technology for connecting to databases. Next I will introduce how to use ado to dynamically create access databases. To use ado, you must introduce Microsoft's two dynamic connection libraries msadox. dll and msado15.dll: # pragmawarning (disable: 4146) # importc: ProgramFilesCommonFilessystem
Currently, ado technology has become the mainstream technology for connecting to databases. Next I will introduce how to use ado to dynamically create access databases. To use ado, you must introduce Microsoft's two dynamic connection libraries msadox. dll and msado15.dll: # pragma warning (disable: 4146) # import c:/Program Files/Common Files/system/
Ado technology has become a connectionDatabaseThe following describes how to use ado to dynamicallyCreateAccessDatabase.
To use ado, Microsoft's two dynamic connection libraries msadox. dll and msado15.dll must be introduced:
# Pragma warning (disable: 4146)
# Import "c:/Program Files/Common Files/system/ado/msadox. dll"
# Import "c:/Program Files/Common Files/system/ado/msado15.dll" no_namespace rename ("EOF", "EndOfFile ")
# Pragma warning (default: 4146)
Add the above Code to the stdafx. h file. Since ado is a com component, you must initialize the com environment before using ado:
CoInitialize (NULL );
Below isDatabaseMediumCreateExample of the SQL statement of a table:
HRESULT hr = S_ OK;
CString strcnn (_ T ("Provider = Microsoft. JET. OLEDB.4.0; Data source = D: // test. mdb "));
Try
{
ADOX: _ CatalogPtr m_pCatalog = NULL;
Hr = m_pCatalog.CreateInstance (_ uuidof (ADOX: Catalog ));
If (FAILED (hr ))
{
_ Com_issue_error (hr );
}
Else
{
// The path here can be customizedCreateI simply entered D: // test. mdb13.
// M_pCatalog-> Create ("Provider = Microsoft. JET. OLEDB.4.0; Data source = D: // test. mdb ");
M_pCatalog-> Create (_ bstr_t (strcnn); // Create MDB
}
}
Catch (_ com_error & e)
{
AfxMessageBox (e. ErrorMessage ());
}