A complete ODBC database program

Source: Internet
Author: User

 


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