We all know that there are two options for developing database programs with VC: ODBC or ADO. ODBC appeared earlier, with many users. ADO is a technology that Microsoft is vigorously supporting and developing. programmers who are committed to learning VC should learn this technology now.
In this example, I still use ODBC, which is more familiar to me. There are two key points for Program Implementation: I. Application of ODBC. Ii. Use of the LISTCONTROL control. The CRecordView class is used for the program view. For detailed configuration, refer to the source program. The program is mainly implemented in the View File. The functions include adding records, deleting records, modifying records, sorting records, and searching records, which are intuitively displayed in the control table. This program uses the AECESS database, of course, ORACLE and other databases. The interface of the entire program is concise and intuitive (SEE ).
The procedure is as follows:
First, determine the table style based on the database content. The design is as follows:
1. Add the Contrl variable m_ListCtrl to the List Control in the view header file. Add the following statement to the OnInitialUpdate () function of the file:
// Set the table question and column width
M_ListCtrl.SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
M_ListCtrl.InsertColumn (0, _ T ("student ID"), LVCFMT_IMAGE | LVCFMT_LEFT );
M_ListCtrl.InsertColumn (1, _ T ("name "));
M_ListCtrl.InsertColumn (2, _ T ("math "));
M_ListCtrl.InsertColumn (3, _ T ("English "));
Int j;
For (j = 0; j <4; j ++)
{
M_ListCtrl.SetColumnWidth (j, 90 );
}
In this way, the list is set and the column width is set. Pay special attention to the following:Set the report attribute in Styles on the properties page of the List Control. When the program runs, all records are required to be displayed, so a Show () function is added. For its reusability, I encapsulate it. You can see its benefits in the subsequent programs. The Show () function is as follows:
IntCLhwyView: Show ()
{
Int I = 0;
M_pSet-> MoveFirst ();
Do
{
CString s;
S. Format ("% d", m_pSet-> m_column1 );
M_ListCtrl.InsertItem (I, s, 0 );
M_ListCtrl.SetItemText (I, 1, m_pSet-> m_column2 );
S. Format ("% d", m_pSet-> m_column3 );
M_ListCtrl.SetItemText (I, 2, s );
S. Format ("% d", m_pSet-> m_column4 );
M_ListCtrl.SetItemText (I, 3, s );
I ++;
M_pSet-> MoveNext ();