Head file definition
/ * Description: This is an ADO class that can be implemented with ADO to operate * // * 1. Connect database * /// * 2. Query the database or association table * // * 3. Execute SQL statements Insert modification deletion Operation * // * 4. Turn off the database * /
#include "stdafx.h" #include "adoEx.h"
#ifdef _debug # undef this_filestatic char this_file [] = __ file __; # Define new debug_new # Endif
CADOEX :: Cadoex () {m_bopen = false; file: // Instance m_pconnection.createinstance (_UUIDOF (connection));}
Cadoex :: ~ Cadoex () {
IF (RETRECORDSETPTR! = NULL) RETRECORDSETPTR-> Close (); RetRecordSetPtr = NULL;
CLOSEADO ();
M_Bopen = false;} file: // Open ADO Database Bool Cadoex :: Openado (LPCTSTR LPDSN, LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTS {BOOL BRET = false; if (m_bopen) Return True;
Try {file: // connect database hresult = m_pConnection-> Open (lpdsn, lpuid, lppwd, 0);
IF ("Open ADO Database Succeed! / N"); m_bopen = true; bret = true;} else {m_bopen = false; bret = false;}} file: // end of try catch (_COM_ERROR E) {MEMSET (LPBUFF, 0x00, 500); Sprintf (LPBUF, "Output / N:% S" when opening the database, E.ErrorMessage ()); AfxMessageBox (lpbuff);
Return Bret;
/ * ADO general query function * / / * call parameters: the correct SQL query statement. * // * You can query a table, you can also query multiple tables * // * Return a record set * // If successful Returns a non-empty record * // * Returns a NULL record set * / _ recordSTPTR CADOEX :: query (lpctstr lpquery) {RetRecordSetPtr = null; _variant_t vrecsaffected;
IF (! m_bopen) return null;
try {retRecordsetPtr = m_pConnection-> Execute (lpQuery, & vRecsAffected, adOptionUnspecified);} catch (_com_error e) {memset (lpBuff, 0x00,500); sprintf (lpBuff, "exception occurs when querying the database tables / n:% s", E.ErrorMessage ()); AfXMessageBox (LPBUF);} Return RetRecordSetPtr;}
/ * ADO general query function * / / * call parameters: correct SQL query statement. * // * You can insert a table to modify the modified delete operation * // * If successful return true * // * If the failure returns * / bool CADOEX :: EXECUTE (LPCTSTR LPEXCUTE) {bool Bret = false; _variant_t vrecsaftructed;
IF (! m_bopen) return null;
try {m_pConnection-> Execute (lpExcute, & vRecsAffected, adOptionUnspecified); bRet = TRUE;} catch (_com_error e) {bRet = FALSE; sprintf (lpBuff, "exception occurs when Database Table /; memset (lpBuff, 0x00,500) N:% s ", E.ErrorMessage ()); AFXMessageBox (lpbuff);
Return Bret;
Bool Cadoex :: Closeado () {if (m_bopen) {m_pconnection-> close (); trace0 ("Close Ado Connection! / N");
Return True;}
File: // ---------------------------------------------- --------------------------------------------
File: // adoEx implementation
/ * Description: This is an ADO class that can be implemented with ADO to operate * // * 1. Connect database * /// * 2. Query the database or association table * // * 3. Execute SQL statements Insert modification deletion Operation * // * 4. Turn off the database * /
#include "stdafx.h" #include "adoEx.h"
#ifdef _debug # undef this_filestatic char this_file [] = __ file __; # Define new debug_new # Endif
//// construction / destruction //
Cadoex :: Cadoex () {m_bopen = false; file: // Initialization Connection instance m_pConnection.createInstance (_UUIDOF (Connection));} Cadoex :: ~ Cadoex () {
IF (RETRECORDSETPTR! = NULL) RETRECORDSETPTR-> Close (); RetRecordSetPtr = NULL;
CLOSEADO ();
M_Bopen = false;} file: // Open ADO Database Bool Cadoex :: Openado (LPCTSTR LPDSN, LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTS {BOOL BRET = false; if (m_bopen) Return True;
Try {file: // connect database hresult = m_pConnection-> Open (lpdsn, lpuid, lppwd, 0);
IF ("Open ADO Database Succeed! / N"); m_bopen = true; bret = true;} else {m_bopen = false; bret = false;}} file: // end of try catch (_COM_ERROR E) {MEMSET (LPBUFF, 0x00, 500); Sprintf (LPBUF, "Output / N:% S" when opening the database, E.ErrorMessage ()); AfxMessageBox (lpbuff);
Return Bret;
/ * ADO general query function * / / * call parameters: the correct SQL query statement. * // * You can query a table, you can also query multiple tables * // * Return a record set * // If successful Returns a non-empty record * // * Returns a NULL record set * / _ recordSTPTR CADOEX :: query (lpctstr lpquery) {RetRecordSetPtr = null; _variant_t vrecsaffected;
IF (! m_bopen) return null;
try {retRecordsetPtr = m_pConnection-> Execute (lpQuery, & vRecsAffected, adOptionUnspecified);} catch (_com_error e) {memset (lpBuff, 0x00,500); sprintf (lpBuff, "exception occurs when querying the database tables / n:% s", E.ERRORMESSAGE ()); AFXMessageBox (LPBUFF);
Return RetRecordSetptr;}
/ * ADO general query function * / / * call parameters: correct SQL query statement. * // * You can insert a table to modify the modified delete operation * // * If successful return true * // * If the failure returns * / bool CADOEX :: EXECUTE (LPCTSTR LPEXCUTE) {BOOL BRET = false; _variant_t vrecsaffected; if (! M_bopen) return null;
try {m_pConnection-> Execute (lpExcute, & vRecsAffected, adOptionUnspecified); bRet = TRUE;} catch (_com_error e) {bRet = FALSE; sprintf (lpBuff, "exception occurs when Database Table /; memset (lpBuff, 0x00,500) N:% s ", E.ErrorMessage ()); AFXMessageBox (lpbuff);
Return Bret;
Bool Cadoex :: Closeado () {if (m_bopen) {m_pconnection-> close (); trace0 ("Close Ado Connection! / N");
Return True;}