Some experiences on DAO Database Programming

Source: Internet
Author: User

 

 

1. How to add database support to programs not supported by the database when creating a database

 

In the dialog boxDAO-Access is used as an example:

1.1 Use the Class Wizard to create a Class. Name: "mydb", Base Class: "DaoRecordset", and select the correct data source and table.

Note: Vc6 cannot directly support access2000. If you want to use it, convert it to Version 97 first.

 

1.2 add # include "afxdao. h" to the mydb header file. In the dialog box, add # include "mydb. h" to the Class header file ".

 

1.3 Test: Add a button to the dialog box class and add the following code to the response function:

Mydb db;

Db. Open ();

MessageBox (db. m_answerA );

Db. Close ();

Assume that my database table containsAnswerA field.

 

2. How to manually add static bindings to programs without static bindings to other controls in the database.

 

Take the above as an Example. Delete the previous button and its message processing function first. Add an EDIT control.

 

2.1 Declaration: Add mydb * rec to the AFX_DATA header file in the dialog box, as follows:

// {AFX_DATA (CAaaDlg)

Enum {IDD = IDD_AAA_DIALOG };

Mydb * rec;

// NOTE: the ClassWizard will add data members here

//} AFX_DATA

 

2.2 BIND: add the member variable m_amswerA to the edit Control in the Class Wizard. (select in The Wizard)

 

2.3 initialization: add it to the constructor in the dialog box

Rec = new mydb;

Rec-> Open ();

2.4 destroy: In the response dialog box WM_CLOSE, add the Message Processing code:

Rec-> Close ();

Delete rec;

2.5 test: After compilation and running, you can see the database content in the EDIT box. The only drawback is that the display cannot be updated automatically. You need to manually UpdateData (0 );

 

3. How to ensure that the above programs can still be copied to another machine?. (The database is also copied to the same directory)

 

Just nowThe content of the mydb getdefadbdbname () function is changed:

Char str [255];

GetCurrentDirectory (255, str );

Strcat (str, "\ my. mdb ");

Return _ T (str );

 

 

 

Related Article

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.