实现了简单的数据库连接,得到记录集,得到二维数组,执行某个语句,其实这个类可以继续扩充,比如先读取变量,得到执行次数,简单分页等等。。,篇幅有限,自己扩充 '---------------------------------------------- '数据库操作 '---------------------------------------------- '简化的数据类 Class dbconn public connstr,conn,queryCount,die_err private connstate Private Sub Class_Initialize queryCount=0 connstate = false die_err = true End Sub '构造 Sub Conn_Open on error resume next set conn = server.CreateObject("adodb.connection") conn.connectiontimeout = 120 Conn.Open connstr if err then if die_err = true then die "数据库连接错误!" else connstate= true end if End Sub '得到记录集 Function getRs(byval sqlStr,byval vtype) On Error Resume Next if cint(vtype) <> 3 then vtype =1 end if if connstate = false then call Conn_Open set getrs = server.CreateObject("ADODB.RECORDSET") getrs.open sqlStr,conn,1,vtype queryCount = queryCount+1 if Err then if die_err = true then die sqlStr if die_err = true then die "数据库得到记录集错误!" end if End Function '得到单一的值 Function getVal(byval sqlstr) On Error Resume Next if connstate = false then call Conn_Open dim rs : set rs =conn.execute(sqlstr) if rs.eof then getVal ="" else getVal = rs(0) end if rs.close : set rs = nothing End Function Function exec(Byval sqlstr) if connstate = false then call Conn_Open conn.execute(sqlstr) End Function '得到数组 Function getArray(Byval sqlstr) on error resume next if connstate = false then call Conn_Open dim rs : set rs =conn.execute(sqlstr) if rs.eof then getArray = "" else getArray = rs.getrows rs.close : set rs = nothing queryCount = queryCount+1 if Err then if die_err = true then die "数据库得到数组错误!" end if End Function '析构 Public Sub Class_Terminate() if connstate = true or isObject(conn) then conn.close:set conn = nothing End Sub End Class