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