Asp类 的数据库领域
代码如下:
<%@language="vbscript" codepage="936"%>
<%
class newsclass
private zzcn,conn,cnnstr
private title_p,id_p
'对象初始化
private sub class_initialize()
'response.write "初始化
"
call newsconnstart()
end sub
'析构函数,在使用 set nothing 释放对象时,自动执行
private sub class_terminate()
'response.write "释放对象 事件:class_terminate
"
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 & "
"
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&"
"
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
"
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
%>
<%@language="vbscript" codepage="936"%>
<%
class newsclass
private zzcn,conn,cnnstr
private title_p,id_p
'对象初始化
private sub class_initialize()
'response.write "初始化
"
call newsconnstart()
end sub
'析构函数,在使用 set nothing 释放对象时,自动执行
private sub class_terminate()
'response.write "释放对象 事件:class_terminate
"
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 & "
"
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&"
"
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
"
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
%>