One night program finally found out the problem, write down, to remind himself, programming needs care!
I have recently been a mess for a management system, and I have the main function to be realized, but I don't have a moment. When I added the data, when the query record, the previous result of the display in ListCtrl will always be replaced by the current result.
// // Connect the database // CDB DB; _RecordSetPtr RS;
Cstring strsql; cstring straTemp;
STRSQL = "SELECT I_ID, I_TIME, I_IP, I_DOMAIN, I_PORT, I_HOSTTYPE, I_NATION, I_STATUS"; strsql = "from info order by i_id desc";
// / / Execute SQL statement // rs = db.exec (strsql);
For (int NITEM = 0;! rs-> adoeof; nitem ) {strtemp.format ("% d", rs-> getCollect ("i_id"). intVal); m_list.insertitem (nitem, strtemp); m_list.setitemtext (NItem, 1, IS_VT_NULL ("i_ip"). VT)? "" "" "(_ bstr_t) rs-> getCollect (" i_ip "))); M_List.SetItemtext (NITEM, 2 , Is_vt_null (rs-> getCollect ("i_domain"). VT)? "" "" (_ Bstr_t) rs-> getCollect ("i_domain"))); M_List.SetItemtext (NITEM, 3, IS_VT_NULL (RS -> getCollect ("i_port"). VT)? "": (_ Bstr_t) rs-> getCollect ("i_port")); m_list.setitemtext (NITEM, 4, IS_VT_NULL (RS-> getCollect) "i_hosttype"). VT)? "": (char *) ((_ bstr_t) rs-> getCollect ("i_hosttype")); m_list.setitemtext (NITEM, 5, IS_VT_NULL (RS-> getCollect ("i_nation") .vt)? "": (_ bstr_t) rs-> getCollect ("i_nation"))); strTemp.empty (); startemp.format ("% s", rs-> getCollect ("i_status" ) .bval> 0? "available": "fail"); m_list.setitemtext (NITEM, 6, strTemp); strTemp.empty (); m_list.setitemtext (NITEM, 7, (char *) ((_ bstr_t) RS- > GetCollect ("i_time"))));
RS-> MoveNext ();} RS-> Close (); db.close ();
The first reaction, modified the Order By ... DESC to ASC, and the program can display the result normally. But this does not meet my output requirements, through a while debug, finding, no matter what kind of change, the program is always output. Is the ListCtrl under Win2k3 output in ascending order? If this is, it is not difficult for this code to work, just set the NITEM parameters in InsertItem and SetItemText to 0, but this is a more deadboard that changes to the database (VC's operation is enough to operate) I have a headache), but also judge the sorting method in SQL. I didn't want to understand the reasons for a long time, I can't let me realize a listctrl in myself. Still don't die, if the function is implemented, it must be implemented by setting the control properties. Open the window, find that listctr, found in the Style tab, the sort property selection is ascending, faint, this thing I remember to be none, change to none, ok! The problem is solved.
This is a very simple question, it seems that the program is still careful, save always stumble in some small places.