ASP中乙個資料庫操作類

2021-04-13 07:07:38 字數 3372 閱讀 7746

'是否隱藏錯誤資訊的選項,true=顯示,false=隱藏

const is_debug = true

class conn

public objcn

private connstr

private errinfo

private executecnt

private time_start

private m_datebasetype

private connectionstring

'初始化類

private sub class_initialize()

time_start = timer()

set errinfo = new errqueue

executecnt = 0

end sub

'設定資料庫連線字串 

public sub setconnstring(connectionstring, datebasetype)  

connstr = connectionstring

if datebasetype = 1 then

m_datebasetype = "sql server"

else

m_datebasetype = "access"

end if

end sub

'取得錯誤數量

public property get errorscount()

errorscount = errinfo.errorscount

end property

'取得資料數型別

public property get datetype()

datetype = m_datebasetype

end property

'執行sql查詢的次數 

public property get querycount()

querycount = executecnt

end property

'以列表型式顯示錯誤資訊

public sub printerr(erroption)

errinfo.showerrors erroption

end sub

'顯示成功資訊,並轉向到指定的頁面.

public sub showsuccalert(s_info, changeurl)

response.clear

response.write ""

if changeurl = "closewindow" then

response.write ""

response.end

elseif len(changeurl) > 0 then

response.write ""

response.end

end if

end sub

'顯示錯誤資訊彈出視窗,並轉向到指定頁面

public sub showerralert(s_info, changeurl)

response.clear

response.write ""

'  & "/n/n共執行資料庫查詢" & querycount & "次;');"

if changeurl <> "" then

response.write ""

else

response.write ""

end if

response.end

end sub

'新增一條錯誤資訊

public sub adderr(s_err)

errinfo.additem s_err

end sub

'析構函式

private sub class_terminate

on error resume next

set errinfo = nothing

objcn.close

set objcn = nothing

end sub

end class

'錯誤資訊佇列

class errqueue

private errorsqueue

public sub additem(s_info)

dim i

i = errorscount

if i = 0 then

redim errorsqueue(1)

errorsqueue(1) = s_info

else

redim preserve errorsqueue(i + 1)

errorsqueue(i + 1) = s_info

end if

end sub

public sub showerrors(erroption)

dim i, s_output

i = errorscount

if i > 0 then

dim m

for m = 1 to i

s_output = s_output & "" & errorsqueue(m) & "" & vbcrlf

next

redim errorsqueue(0)

response.write "您在 " & erroption & " 時發生錯誤:"

response.write(s_output)

response.end

end if

end sub

public function geterrorinfo()

dim i

i = errorscount

if i > 0 then

dim m

for m = 1 to i

geterrorinfo = geterrorinfo & "" & errorsqueue(m)

next

redim errorsqueue(0)

end if

end function

public property get errorscount()

if not isarray(errorsqueue) then

errorscount = 0

else

errorscount = ubound(errorsqueue)

end if

end property

public sub clear()

redim errorsqueue(0)

end sub

private sub class_terminate

set errorsqueue = nothing

end sub

end class 

asp資料庫操作類

class quickdb private conn,connstr private sqldatabasename,sqlpassword,sqlusername,sqllocalname,sqlnowstring public rs private sub class initialize sq...

Django中乙個專案使用多個資料庫

1.修改專案的 settings 配置 在 settings.py 中配置需要連線的多個資料庫連線串 2.設定資料庫的路由規則方法 在settings.py中配置database routers project 建立的django專案名稱 project name database router 定...

乙個資料庫操作類的例項(二 Provider類)

using system namespace com.joybase.db 資料庫連線型別,即判斷是system.data.sqlclient型別或者是system.data.oledb型別的。private static dbtype databasetype else 其它則返回system.d...