Asp类 的数据库领域
更新时间:2006年10月18日 00:00:00 作者:
奶奶的,Asp类 是真不好学啊,看着简单,可真到用的时候,网上的代码是都报错啊!!
郁闷了恩久!! 3天了,终于调试出来了,一个简单的 数据库类模型,不敢独享,拿出来大家分享吧!
本作品 归 站长中国 www.zzcn.net 彭彭所有 ,你们拷贝的时候不许去掉版权,否则拷贝的人全家死光光!!!!呵呵。。:)
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
' 彭彭制作的一个新闻类 敬请笑纳 【站长中国】 http://www.zzcn.net QQ:76526211
class NewsClass
Private zzcn,conn,cnnstr
private title_p,id_p
'对象初始化
Private Sub Class_Initialize()
'response.write "初始化<br>"
call newsconnstart()
End Sub
'析构函数,在使用 set nothing 释放对象时,自动执行
Private Sub Class_Terminate()
'response.Write "释放对象 事件:Class_Terminate<br>"
call newsconnend()
end sub
'数据库链接函数
Private sub newsconnstart()
Set conn = Server.createObject("ADODB.Connection")
cnnstr="DRIVER={Microsoft Access Driver (*.mdb)}; "
cnnstr=cnnstr & "DBQ=" & Server.MapPath("admin/WataVase/%29to-dream.mdb")
conn.Open cnnstr
'response.write cnnstr & "<br>"
End sub
Private sub newsconnend()
conn.close
set conn = nothing
End sub
'=========================================
'函数名 getrs()
'获得 某个栏目 的 一条 记录集
'栏目名 lanmu
'每页几条记录 k
'第几页 page
'第几条记录 n
'日期 riqi 1 为按日期逆序 0 为升序
'=========================================
Public Function getrs(ByVal lanmu,ByVal k,ByVal page,ByVal n,ByVal riqi)
sql = "Select * From ArticleClass where ClassName = '"&lanmu&"' order By ClassID Desc"
'response.write sql&"<br>"
set rs=Server.CreateObject("adodb.recordset")
rs.open sql, conn, 1, 1
if not rs.eof then
ClassID_p = rs("ClassID")
end if
rs.close
set rs = nothing
if riqi = 1 then
riqi_p = " order By UpdateTime Desc"
else
riqi_p = ""
end if
sql = "Select * From Article where ClassID = "&ClassID_p&""&riqi_p
set rs=Server.CreateObject("adodb.recordset")
rs.open sql, conn, 1, 1
rs.PageSize = k
if not rs.eof then
rs.AbsolutePage = page
end if
i = 0
do while not rs.eof and i < n
i = i + 1
rs.movenext
loop
'response.write "rs<br>"
if n = i then
title_p = rs("Title")
id_p = rs("ArticleID")
'response.write title_p
'response.write id_p
else
title_p = null
id_p = null
end if
rs.close
set rs = nothing
end Function
'----------------------------------------
'
'属性写 标题
Public Property Let title(byval v)
title_p = v
End Property
'属性读 标题
Public Property Get title()
title = title_p
End Property
'属性写 标题ID
Public Property Let id(byval v)
id_p = v
End Property
'属性读 标题ID
Public Property Get id()
id = id_p
End Property
end class
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Asp 数据库 类 彭彭制作 QQ:76526211</title>
</head>
<body>
<%
dim news
set news = new NewsClass
call news.getrs("网站收藏",1,1,1,1)
response.write news.id & " " & news.title
set news = nothing
%>
</body>
</html>
郁闷了恩久!! 3天了,终于调试出来了,一个简单的 数据库类模型,不敢独享,拿出来大家分享吧!
本作品 归 站长中国 www.zzcn.net 彭彭所有 ,你们拷贝的时候不许去掉版权,否则拷贝的人全家死光光!!!!呵呵。。:)
复制代码 代码如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
' 彭彭制作的一个新闻类 敬请笑纳 【站长中国】 http://www.zzcn.net QQ:76526211
class NewsClass
Private zzcn,conn,cnnstr
private title_p,id_p
'对象初始化
Private Sub Class_Initialize()
'response.write "初始化<br>"
call newsconnstart()
End Sub
'析构函数,在使用 set nothing 释放对象时,自动执行
Private Sub Class_Terminate()
'response.Write "释放对象 事件:Class_Terminate<br>"
call newsconnend()
end sub
'数据库链接函数
Private sub newsconnstart()
Set conn = Server.createObject("ADODB.Connection")
cnnstr="DRIVER={Microsoft Access Driver (*.mdb)}; "
cnnstr=cnnstr & "DBQ=" & Server.MapPath("admin/WataVase/%29to-dream.mdb")
conn.Open cnnstr
'response.write cnnstr & "<br>"
End sub
Private sub newsconnend()
conn.close
set conn = nothing
End sub
'=========================================
'函数名 getrs()
'获得 某个栏目 的 一条 记录集
'栏目名 lanmu
'每页几条记录 k
'第几页 page
'第几条记录 n
'日期 riqi 1 为按日期逆序 0 为升序
'=========================================
Public Function getrs(ByVal lanmu,ByVal k,ByVal page,ByVal n,ByVal riqi)
sql = "Select * From ArticleClass where ClassName = '"&lanmu&"' order By ClassID Desc"
'response.write sql&"<br>"
set rs=Server.CreateObject("adodb.recordset")
rs.open sql, conn, 1, 1
if not rs.eof then
ClassID_p = rs("ClassID")
end if
rs.close
set rs = nothing
if riqi = 1 then
riqi_p = " order By UpdateTime Desc"
else
riqi_p = ""
end if
sql = "Select * From Article where ClassID = "&ClassID_p&""&riqi_p
set rs=Server.CreateObject("adodb.recordset")
rs.open sql, conn, 1, 1
rs.PageSize = k
if not rs.eof then
rs.AbsolutePage = page
end if
i = 0
do while not rs.eof and i < n
i = i + 1
rs.movenext
loop
'response.write "rs<br>"
if n = i then
title_p = rs("Title")
id_p = rs("ArticleID")
'response.write title_p
'response.write id_p
else
title_p = null
id_p = null
end if
rs.close
set rs = nothing
end Function
'----------------------------------------
'
'属性写 标题
Public Property Let title(byval v)
title_p = v
End Property
'属性读 标题
Public Property Get title()
title = title_p
End Property
'属性写 标题ID
Public Property Let id(byval v)
id_p = v
End Property
'属性读 标题ID
Public Property Get id()
id = id_p
End Property
end class
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Asp 数据库 类 彭彭制作 QQ:76526211</title>
</head>
<body>
<%
dim news
set news = new NewsClass
call news.getrs("网站收藏",1,1,1,1)
response.write news.id & " " & news.title
set news = nothing
%>
</body>
</html>
最新评论