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 );