#define OK 0 typedef int RESULT; void InitUserComboBox() { CMainFrame *pMainFrame = (CMainFrame*)AfxGetMainWnd(); MYSQL *pMySQL; // Initialize a MYSQL object. pMySQL = mysql_init(NULL); if (pMySQL == NULL) { return; } // Establish a connection to MYSQL database pMySQL = mysql_real_connect(pMySQL, pMainFrame->strMySQLIP, pMainFrame->strMySQLUser, pMainFrame->strMySQLPass, pMainFrame->strMySQLDB, pMainFrame->nMySQLPort, NULL, 0); if (pMySQL == NULL) { return; } // Set the default character set for the current connection mysql_set_character_set(pMySQL, "GBK"); // specify the default (current) database RESULT ret; ret = mysql_select_db(pMySQL, "HrINetDB"); if (ret != OK) { mysql_close(pMySQL); return; } // Execute a query CString strSql = _T(" select empName from T_SC_UserManager where iState<>'0' "); ret = mysql_query(pMySQL, strSql); if (ret != OK) { mysql_close(pMySQL); return; } // Store result set MYSQL_RES *pRes; pRes = mysql_store_result(pMySQL); if (pRes == NULL) { mysql_close(pMySQL); return; } // Get the number of result set int num = mysql_num_rows(pRes); if (num <= 0) { mysql_free_result(pRes); mysql_close(pMySQL); return; } // Retrieves the next row of a result set MYSQL_ROW row; while (row = mysql_fetch_row(pRes)) { m_comUser.AddString(row[0]); } // Frees the memory allocated for a result set mysql_free_result(pRes); // Closes a previously opened connection mysql_close(pMySQL); }