ADO封裝類的實現

2021-04-01 02:41:15 字數 2403 閱讀 9420

宣告:

///用來訪問資料庫的類。要用次類的話,程式中應該進行的初始化工作為:

/在stdafx.h中包含下面一句,用來將ado的dll檔案引入到程式中:

/#import "c:/program files/***mon files/system/ado/msado15.dll" no_namespace rename("eof","adoeof")

/在主程序的initinstance()中要新增的語句,用來初始化ole

/ if(!afxoleinit())/ /

關於m_precordset指標的釋放問題

在.cpp檔案中要包含"cpfile.h"

///class cpdata 

;實現:

//// 建構函式

////預設的建構函式

cpdata::cpdata()

//傳入引數的建構函式

cpdata::cpdata(_connectionptr pconnection)

//// 析構函式

//cpdata::~cpdata()

////簡單操作函式

//得到操作結果的行數

long cpdata::getresultrow()

//得到操組結果的列數

long cpdata::getresultcol()

//得到操作結果

_recordsetptr cpdata::getresult()

//////連線操作

/////連線到資料庫

//1.連線字串可以自己構造,也可以從檔案中讀出

bool cpdata::connect(cstring struser,cstring strpassword,cstring strfilename,int noptions,cstring strconstr)

else

//進行連線

//連線失敗

if(failed(hr))

}catch(_***_error&e)

return true;

}//斷開連線

void cpdata::disconnect()

//////更新操作

///bool cpdata::execute(cstring strsql)

catch(_***_error&e)

return true;

}///

///查詢操作

///bool cpdata::select(cstring strsql)

catch(_***_error&e)

return true;

}//查詢語句,負責對僅僅查詢乙個欄位的情況進行處理

//結果存放在cstringarray型別的變數presult中

bool cpdata::select(cstring strsql,cstringarray& result)

else

result.add(value.bstrval);//

m_precordset->movenext();

}m_precordset->close();

return true;

}else

}bool cpdata::selectmulitcol(cstring strsql,cstringarray& result)

else

if(value.vt==7)

else

result.add(value.bstrval);//

}m_precordset->movenext();

}m_precordset->close();

return true;

}else

}//開啟整張表

bool cpdata::opentable(cstring strtable)

catch(_***_error&e)

return true;

}bool cpdata::opentable(cstring strtable,cstringarray& result)

else

if(value.vt==7)

else

result.add(value.bstrval);//

}m_precordset->movenext();

}m_precordset->close();

return true;

}else}/

///關閉結果集

/void cpdata::closerecordset()

bool cpdata::executetrans(cstringarray& asql)

m_pconnection->***mittrans(); 

return true;

}catch(_***_error& e) }

VC 下封裝ADO類以及使用方法

作業系統 windows 7 軟體環境 visual studio 2008 microsoft sql 2005 本次目的 介紹乙個已經封裝的ado類,簡單說明怎麼匯入使用 首先宣告一下,這個封裝的ado類是在 vc知識庫 檢視。在此僅介紹使用此ado封裝類的入門,如連線資料庫,顯示記錄等。乙個測...

MySQL的ADO控制項 實現ADO控制項引用的方法

關係型資料庫系統中的表由行和列組成,這有些類似於excel二維 的樣子。由於excel並不是關係型資料庫管理系統,在使用vba對關係型資料庫進行訪問時,需要通過設定ado來訪問關係型資料庫系統。本文介紹向工程中新增ado引用的方法。1 啟動excel並建立文件,開啟visual basic編輯器,選...

thunk技術實現視窗類的封裝

當前位置 文章中心 技術開發 程式開發 文章內容 減小字型 增大字型 mfc功能已經非常強大,自己做介面庫也許沒什麼意思,但是這個過程中卻能學到很多東西。比如說 視窗類的封裝,從全域性視窗訊息處理到視窗物件訊息處理的對映方法 對介面進行封裝,一般都是乙個視窗乙個類,比如實現乙個最基本的視窗類cmyw...