asp实现简单数据库连接类
实现了简单的数据库连接,得到记录集,得到二维数组,执行某个语句,其实这个类可以继续扩充,比如先读取变量,得到执行次数,简单分页等等。。,篇幅有限,自己扩充
'----------------------------------------------
'数据库操作
'----------------------------------------------
'简化的数据类
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
相关文档:
<bgsound src="wen.mid" loop="0">
<% dim weh
If Time >=#1:00:00 AM# And Time < #6:00:00 PM# Then
weh = "<bgsound src="1.mid" loop="0">"
Else If Time >#6:00:00 AM# And Time < #9:00:00 PM#
weh = "<bgso ......
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> </script>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">
<title ......
此文只是入门,演示了如何用实体类存储数据,无实际意义。后面有陆续更新优化。(以后的文章中将陆续实现无需声明具体类自动存储数据,和简单的性能优化)
在asp程序开发过程中,结构数据的存储一直是个问题,asp的数组一直很弱,而且不能自解释, ......
遍历XML文档
对于下面的一段XML代码:
XML文档实例books.xml,如下所示:
<?xml version="1.0" encoding="gb2312" ?>
<books>
<book status="已售完">
<author>破破</author>
<title>XML入门</title >
</book>
<book statu ......