Use custom class CSetoDBC (2)

xiaoxiao2021-03-06  141

1, theoretically supports any database, as an example, the structure is as follows 2, the relevant information is recorded in the INI or registry, its structure is: [Data Source] DSN = Testodbcuid = adminPwd = 3, dynamically bind a class, change GetDefaultConnectCString CCharacterSet :: GetDefaultConnect () {CSetODBC dlg; CString strConnect = "ODBC;" dlg.GetConnectStr (); return _T (strConnect); // dynamic obtain ODBC // return _T ( "ODBC; DSN = TestODBC") } 4, use void ctestodbcdlg :: onRecordset () {ccharacterset {csetoDBC DLG; rs.Open (DLG.GetWriteDBStyle ()); {// increase record rs.addNew (); rs.m_name = "r韦"; rs.m_age = 60; rs.m_country = "Wei"; rs.Update ();} {// Modify Record rs.movefirst (); while (! rs.iseof ()) {IF ("r韦 == Rs.m_name) {r.EDit (); rs.m_age = 59; rs.Update ();}}}} {// Delete Record}} {// Delete Record}}} {// Delete Record}}} {// Delete Record}}} {// Remove Rs.Movefirst (); While (! rs.iseof) )) {IF ("Ciwi" == r.m_name) {r.delete (); rs.ReQuery ();}}}}} {// Display all record rmovefirst (); cstring StrOutput; while (! rs.iseof ()) {cstring strrecord; rs.m_name.trimleft (); rs.m_name.trimright (); rs.m_country.trimleft (); rs.m_country.trimright (); strrecord.format ("Name =% S / TCOUNTRY =% s / TAGE =% D /N "RS.M_NAME ,RS.M_COUNTRY ,RS.M_AGE) ;stroutput = strrecord; rs.movenext ();} afxMessageBox (S Rs.close ();}

转载请注明原文地址:https://www.9cbs.com/read-127419.html

New Post(0)