Access Database Access Implementation in VC/MFC (method 3)

Source: Internet
Author: User
Tags dsn

2

 

Method 3:

 

This method also requires the user to create a data source, but the steps required are much less than method 2.

Create a user table.

Create a data source (Control Panel-> Data Management-> data source double-click-> select file dsn-> Add-> Microsoft Access driver-> manually enter the location and name of the DSN to save-> select (s) and select the created database file-> OK-> OK... completed)

 

Create a project based on the MFC dialog box. Other projects are also supported.

 

Add # include <afxdb. h> to the function header in the main window.

Define a global variable cdatabase cdb1 for the main program;

Add the following code to the output window initialization:

Cdb1.open ("Name of the data source that will be created ");

Add a button to the main window and add the corresponding function of the button.

The processing code in the response function is as follows:

Cstring strtmp = "insert into mydb (susername, ssex) values ('Lee si', 'mal ')";

Cdb1.executesql (strtmp );

 

In this case, the third method is over.

 

PS:

If you want to know more about the cdatabase class, you can search for it online.

For the open () method in the class, there is a connection here to explain it

Http://www.sunxin.org/article/1042.html

 

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.