時間:2015/6/28來源:IT貓撲網(wǎng)作者:網(wǎng)管聯(lián)盟我要評論(0)
數(shù)據(jù)庫操作類在網(wǎng)上一搜一大把,我這并不比那些好,只是是自己寫的,用著更習(xí)慣。所以我這個類沒有什么特別的地方,只是自己用著習(xí)慣罷了,至于效率等方面,歡迎賜教!
程序代碼:
以下為引用的內(nèi)容: <% Class dbClass '------------------------------------------------------------------------- '變量說明 'conn-----------connection對象 'strsql---------執(zhí)行查詢的語句 'vTbName--------查詢分頁的表名 'vPKey----------查詢分頁的表的主鍵 'vPgFields------查詢分頁要顯示的字段 'vPgSize--------查詢分頁每頁顯示的記錄數(shù) 'vCurrPg--------查詢分頁顯示的當(dāng)前頁 'vConditions----查詢分頁的條件 'vOrderBy-------查詢分頁的排序 '------------------------------------------------------------------------- private conn,strsql,vTbName,vPKey,vPgFields,vPgSize,vCurrPg,vConditions,vOrderBy '類的初始化 private Sub Class_Initialize() '當(dāng)是MS Sql數(shù)據(jù)庫時設(shè)置以下兩個變量 'dim dbServer '數(shù)據(jù)庫服務(wù)器的名稱或ip地址 'dim dbname '數(shù)據(jù)庫的名字 dim dbPath '若是access數(shù)據(jù)庫,此處設(shè)置其路徑 dim dbUser '數(shù)據(jù)庫的登錄用戶名 dim dbPass '數(shù)據(jù)庫的登錄密碼 dim connstr dbPath = "/testasp/data/data.mdb" '設(shè)置數(shù)據(jù)庫路徑 dbUser = "admin" dbPass = "123456" '若是access,并且有密碼 connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(dbPath) &_ ";User ID=" & dbUser & ";Password=;Jet OLEDB:Database Password=" & dbPass '若是access,并且沒有密碼 'connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(dbPath) '若是ms-sql數(shù)據(jù)庫 'connstr = "Provider = Sqloledb; User ID = " & dbUser & "; Password = " & dbPass &_ ' "; Initial Catalog = " & dbname & "; Data Source = " & dbServer on error resume next set conn=server.CreateObject("adodb.connection") conn.open connstr errMsg "連接數(shù)據(jù)庫" End Sub '類結(jié)束 Private Sub Class_terminate() conn.close set conn=nothing End Sub '------------------------------------------------------------------------- '給類的變量設(shè)置值 '------------------------------------------------------------------------- '設(shè)置sql語句 Public Property Let sqlStr(Byval Values) strsql=Values End Property '設(shè)置查詢分頁的表名 public property let tbName(Byval Values) vTbName=Values end property '-------------------------------------------------------- '設(shè)置查詢分頁的表的主鍵 public property let pKey(ByVal Values) vPKey=Values end property '-------------------------------------------------------- '設(shè)置顯示的字段 public property let pgFields(ByVal Values) vPgFields=Values end property '-------------------------------------------------------- '設(shè)置每頁顯示的記錄數(shù) public property let pgSize(ByVal Values) vPgSize=Values end property '--------------------------------------------------------- '設(shè)置當(dāng)前顯示的頁數(shù) public property let currPg(ByVal Values) vCurrPg=Values end property '-------------------------------------------------------- '設(shè)置查詢的條件 public property let conditions(ByVal Values) if Len(Values)>0 then vConditions=" where "&Values else vConditions=" where 1=1 " end if end property '------------------------------------------------------- '設(shè)置查詢的排序 public property let orderBy(ByVal Values) if Len(Values)>0 then vOrderBy=" order by "&Values else vOrderBy=Values end if end property '------------------------------------------------------------- '得到記錄總數(shù) public property get vRsCount() if vCurrPg=1 then sqlc="select count("&vPKey&") as Idcount from "&vTbName&" "&vConditions set rsc=server.CreateObject("adodb.recordset") rsc.open sqlc,conn,0,1 RsNum=rsc("IdCount") rsc.close set rsc=nothing if RsNum>0 then response.Cookies("iRecord")=RsNum vRsCount=RsNum else vRsCount=0 end if else vRsCount=request.Cookies("iRecord") end if end property '得到總頁數(shù) public property get vPgCount() iRs 關(guān)鍵詞標(biāo)簽:操作,數(shù)據(jù)庫,自己,教程 相關(guān)閱讀
熱門文章 Active Server Pages 錯誤 'ASP 0131'解決方
相關(guān)下載
人氣排行 ASP下標(biāo)越界的解決方法ASP代碼中如何屏蔽ip地址 禁止某IP段訪問網(wǎng)站“文件共享鎖定數(shù)溢出” 原因及解決方法無法寫入數(shù)據(jù)庫的解決方法如何用ASP來獲取客戶端真實(shí)IP的地址用Asp編程實(shí)現(xiàn)QQ的在線情況查詢ASP常用函數(shù)列表ASP用FSO生成HTML簡單實(shí)例+詳解[原創(chuàng)]
|