Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C++ connects to the database through ADO

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

C++ connects to the database through ADO. The specific steps are as follows:

1. To import the connection ADO library file information, the method

# import "C:\ Program Files\ Common Files\ System\ ado\ msado15.dll" no_namespace rename ("EOF", "adoEOF") rename ("BOF", "adoBOF") / / must have (newline must have\). For vc6 development, it is best to put this sentence in the StdAfx.h header file and above the "# endif", not on the "afxwin.h" header file, otherwise there will be an error.

Using namespace std; / / optional

# pragma warning (disable:4146) / / the warning warning that forbids the 4146 error code is optional (this sentence is placed in "# import..." Above

2. Initialize the COM library environment (that is, load the supporting functions that run ado library files)

CoInitialize (NULL); / / the program is initialized or run when the constructor is executed, and must be called before using the ado function

CoUninitialize (); / / when the destructor or program exits, or directly executes AfxOleInit () before the program execution (in the constructor), there is no need to call CoUnitialize (), because when AfxOleInit () exits, the function also executes the release of COM resources and declares three smart pointers. The functions and functions are as follows: _ ConnectionPtr m_pConn / / it is mainly used to connect m_pConn.CreateInstance (_ _ uuidof (Connection)) to the database; / / to create an instance of an object, you can also use m_pConn.CreateInstance ("ADODB.Connection") _ RecordsetPtr mroompRst; / / it is mainly used for the operation of database records m_pRst.CreateInstance (_ _ uuidof (Connection)); _ CommandPtr m_pCmd / / it is mainly used to execute SQL statements with parameters (if SQL statements without parameters are executed, you can use _ RecordsetPtr) m_pCmd.CreateInstance (_ _ uuidof (Connection)); 4. To release resources after use, close them before releasing them: m_pCmd.Release (); m_pRst.Release (); m_pConn.Release (); / / this pointer resource must be released last, otherwise an error will occur.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report