Connecting to a database

Source: Internet
Author: User




This article is organized by Code Assistant software to publish content unrelated to the software more enjoyable reading, more enjoyable writing, easier publishing









0 connecting the database

#import "C:\Program Files\Common Files\system\ado\msado15.dll" no_namespace rename ("EOF", "adoeof") Rename ("BOF", "Adobof")_connectionptr m_pconnection; Database connection _connectionptr m_pconnectionstu;//Student Information database bool Connectdatabase(); Connecting Database BOOL Cketangapp::connectdatabase(){:: CoInitialize(NULL);Try{Test database Connection HRESULTHR=M_pconnection.createinstance(__uuidof(Connection));if(FAILED(HR)){AfxMessageBox(_t("Create connection instance failed-question"));returnFALSE;}HR=M_pconnection->open(_t("Provider=Microsoft.ACE.OLEDB. A.0;D ATA Source=Shiti.accdb "), _t(""), _t(""), adModeUnknown);if(FAILED(HR)){AfxMessageBox(_t("The SHITI.ACCDB database does not exist or the path is incorrect");}Student Database ConnectionHR=M_pconnectionstu.createinstance(__uuidof(Connection));if(FAILED(HR)){AfxMessageBox(_t("Create connection instance failed-student");returnFALSE;}HR=M_pconnectionstu->open(_t("Provider=Microsoft.ACE.OLEDB. A.0;D ATA Source=Student.accdb "), _t(""), _t(""), adModeUnknown
)
if(FAILED(HR)){AfxMessageBox(_t("The STUDENT.ACCDB database does not exist or the path is incorrect");}}Catch(_com_error&e){AfxMessageBox(_t("The database has been opened or not present or the path is incorrect");;returnFALSE;}}intCketangapp::ExitInstance() {Todo:addyourSpecializedCode Hereand/orPager theBaseclassif(M_pconnection)if(M_pconnection->state)James M_pconnection->Close();if(M_pconnectionstu)if(M_pconnectionstu->state)James M_pconnectionstu->Close(); Gdiplusshutdown(Gdiplustoken);returnCWINAPP::ExitInstance();}

Connecting to a database

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.