Mfc odbc programming

Source: Internet
Author: User

To simplify the writing of database applications, Microsoft encapsulates the odbc api interfaces in MFC, which is the mfc odbc and implements the object-oriented database programming interface.

MFC encapsulates ODBC APIs mainly by developing the cdatabase class and the crecordset class.

The cdatabase class is mainly used to establish the connection between applications and data sources.

The crecordset class is used to operate datasets.

Record query: It mainly uses the open () method of the crecordset class and the requery () member function. Before using the crecordset class object, you must use the crecordset member function open () to obtain a valid record set. Once you have used the open () function, you can use the requery () function to query again.

Add record: Only addnew () function is used, but it must be enabled in the allowed mode of the database.

Delete record: the delete () function is called. You do not need to call the update () function after the delete () function is used.

Record modification: after calling the Edit () function, you must call the update () function to save the Modification result to the database.

Undo database update: If you want to undo the original operation after adding, deleting, or editing a record, you should use the move () function before the update () function. Crecordset: Move (afx_move_refresh); this function is used to undo the Add or modify mode and restore the current record before the Add or modify mode. The value of afx_move_refresh is zero.

Directly execute the SQL operation: You need to call the executesql () function of the cdatabase class. It should be noted that because the data operation statements provided by different DBMS are different, direct execution of SQL statements may damage the DBMS independence of the software. Therefore, such operations should be used with caution in applications.

The database operation process of mfc odbc:

First, the application should first establish a connection with the ODBC Data source. This process is implemented using the open () function of the cdatabase class, then the cdatabase class pointer will be passed to the constructor of the crecordset class to combine the crecordset object with the original data source. After connecting the data source, a large number of operations are concentrated on the dataset. After the operation, close the connection to all Record Sets and then close the connection to the data source.

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.