The other day, I got a little thing to ACCESS the ACCESS database, and it took some effort to get it done. Although it is still somewhat unsatisfactory, it can still be used after all. Here we will share our implementation methods and experiences. Everything in it is available on the Internet, but here it is the most comprehensive. Vcmfc access to the ACCESS database method create a dialog-based
The other day, I got a little thing to ACCESS the ACCESS database, and it took some effort to get it done. Although it is still somewhat unsatisfactory, it can still be used after all. Here we will share our implementation methods and experiences. Everything in it is available on the Internet, but here it is the most comprehensive. Method 1: 1 create a dialog-Based ACCESS Database
GetAccessACCESSDatabaseIt takes some effort to get it done.
Although it is still somewhat unsatisfactory, it can still be used after all,
Share your ownImplementationMethods and experience.
Everything in it is available on the Internet, but here it is the most comprehensive.
VC/MFCAccessACCESSDatabase
Method 1:
1. Create a dialog box-based application.
Put two ActiveX Controls: Microsoft ADO Data Control, version 6.0... and Microsoft DataGrid Control. If Version 6.0 does not have two spaces, install the OFFICE component.
2. Set Properties for the control.
1) Set Properties for ADO Data Control: Control-> Use Connection String-> Build
In the displayed dialog box, choose Microsoft Jet 4.0 ole db Provider> next> select or enterDatabaseName, select the createdDatabaseFile, for example, d:/test_db/testdb. mdb. The password is blank by default. If the user table has a password, enter the password, select "allow Save Password"-> click "test connection". If "test connection succeeded" is displayed, the data file is ready for use. Click OK and return to the resource editing page of the dialog box.
Set the attributes for the RecordSource option of this control as follows:
Select 1-ad1_text for Command Type.
In Command Text (SQL), enter the SQL statement: select * from mydb;
The properties of the ADO Data Control are set. Disable the Property setting interface.
2) Set Properties for the DataGrid Control.
Select IDC_ADODC1 from the DataSource list.
Disable the Property setting interface.
Compile and run. IfDatabaseIf there is data, it will be displayed in the DataGrid.
Want to perform otherDatabaseFor example:
Next, the procedure above,
Add a variable m_adoDC for ADO Data Control;
Add a variable for Data Grid: m_adoDG;
A button. Double-click it to add a function. Add the following code to the function:
CString strTem = "select * from mydb where SUserName <> 'zhang san '";
// VC 6.0
M_adoDC.SetRecordResource (strTem );
M_adoDC.Refresh ();
// VS 2005/VS 2008
M_adoDC.put_RecordSource (strTem );
M_adoDC.Refresh ();
Compile and run the program.
PS: In this mode, the query results are very good. However, some error messages may occur during the INSERT, UPDATE, and DELETE operations:
// In VC 6.0
The object is closed and cannot be operated.
// In
Windows has triggered a breakpoint in...
Although there are promptsDatabaseThe operation is successful. I have searched the network for this problem, and no one can provide a solution. Similarly, I am not better than them.
This is the end of the first solution.