VS2013 MFC ODBC connection SQL Server database programming (ii)

Source: Internet
Author: User
Tags odbc odbc connection

VS2013 MFC ODBC connection SQL Server database programming (ii)

Reprint Please specify: http://blog.csdn.net/my_acm/article/category/2616577


In the previous article, I explained how to connect to a SQL Server database

Refer to Http://wenku.baidu.com/link?url=h1rGgnhSmnclH2lFexHmlP_SZ2LUDRy5xM4wrbTfYlRXZLj2o0ugMT_ below Pfgrxa1xi2pm8nuueckgqra6d77ziedoymaqluudmaqqz2nqytnm

Some implementations are made, as shown below, and the full functionality implementation will be given in the next article.


First, on the basis of connecting the database, make a picture as shown in the interface, this is not difficult.

You can see that in the connection database score.h, the Cscore class inherits the CRecordset class, with six member variables corresponding to six fields in the database.




We will edit the box, the List control binds the variable separately, as shown in.




Then add the following code to the OnInitDialog function in TestDlg.cpp.



The Add member function void List_all () is used to display all of the data in the table to the list control.




The following is a concrete implementation of List_all.

void Ctestdlg::list_all (CString str) {m_list. Deleteallitems (); Cscore m_score;try{if (M_score. IsOpen ()) M_score. Close (); if (!m_score. Open (Crecordset::snapshot, str)) {MessageBox (l "Failed to open database", l "Database error", MB_OK); return;}} catch (CDBException *e) {e->reporterror ();} int nindex = 0;m_score. MoveFirst (); CString Uscore, Tscore, Fscore;while (!m_score. IsEOF ()) {Lv_item Litem;litem.mask = Lvif_text;litem.iitem = Nindex;litem.isubitem = 0;litem.psztext = L ""; m_list. InsertItem (&litem); m_list. Setitemtext (nindex, 0, M_score.m_stuid); m_list. Setitemtext (nindex, 1, m_score.m_stuname); m_list. Setitemtext (nindex, 2, M_score.m_stuclass); Uscore. Format (L "%3d", M_score.m_usualscore); Tscore. Format (L "%3d", M_score.m_testscore); Fscore. Format (L "%3d", M_score.m_totalscore); m_list. Setitemtext (nindex, 3, Uscore); m_list. Setitemtext (nindex, 4, Tscore); m_list. Setitemtext (nindex, 5, Fscore); M_score. MoveNext (); nindex++;} M_score. Close ();}


VS2013 MFC ODBC connection SQL Server database programming (ii)

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.