Asp类 的数据库领域
程序员文章站
2022-04-14 20:24:35
奶奶的,asp类 是真不好学啊,看着简单,可真到用的时候,网上的代码是都报错啊!! 郁闷了恩久!! 3天了,终于调试出来了,一个简单的 数据库...
奶奶的,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>
上一篇: ASP代码的对象化
下一篇: ASP,FSO遍历目录及目录下文件