Obtain data from mysql and display it in the CList control.

Source: Internet
Author: User

This part is part of the VC and database projects. Later I modified it into a student achievement information management system and used these controls.

To display information in the database, you must first connect to the database and display it in the CList Control. If you do not need to talk about it, directly run the Code:

M_ListValue.DeleteAllItems ();

MYSQL * conn;

Conn = mysql_init (NULL );

If (mysql_real_connect (conn, "localhost", "root", "123456", "mysql", 3306, NULL, 0) = NULL)

{

AfxMessageBox ("database connection failed! ");

}

Else

{

Char * ch_query;

Ch_query = "select * from score ";

If (mysql_real_query (conn, ch_query, (UINT) strlen (ch_query ))! = 0)

{

AfxMessageBox ("the table data is incorrect! ");

}

CString str;

MYSQL_RES * result;

MYSQL_ROW row;

If (! (Result = mysql_use_result (conn )))

{

AfxMessageBox ("failed to read data! ");

}

Int I = 0;

While (row = mysql_fetch_row (result ))

{

Str. Format ("% s", row [0]);

M_ListValue.InsertItem (I, str );

Str. Format ("% s", row [1]);

M_ListValue.SetItemText (I, 1, str );

Str. Format ("% s", row [2]);

M_ListValue.SetItemText (I, 2, str );

Str. Format ("% s", row [3]);

M_ListValue.SetItemText (I, 3, str );

Str. Format ("% s", row [4]);

M_ListValue.SetItemText (I, 4, str );

Str. Format ("% s", row [5]);

M_ListValue.SetItemText (I, 5, str );

Str. Format ("% s", row [6]);

M_ListValue.SetItemText (I, 6, str );

Str. Format ("% s", row [7]);

M_ListValue.SetItemText (I, 7, str );

Str. Format ("% s", row [8]);

M_ListValue.SetItemText (I, 8, str );

I ++;


}

Mysql_free_result (result );

}

M_ListValue is the variable associated with CList Control.


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.