VC creates an access database

Source: Internet
Author: User
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 ());
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.