奶奶的,Asp類 是真不好學(xué)啊,看著簡單,可真到用的時候,網(wǎng)上的代碼是都報錯?。。?
郁悶了恩久??! 3天了,終于調(diào)試出來了,一個簡單的 數(shù)據(jù)庫類模型,不敢獨(dú)享,拿出來大家分享吧!
本作品 歸 站長中國 www.zzcn.net 彭彭所有 ,你們拷貝的時候不許去掉版權(quán),否則拷貝的人全家死光光?。。。『呛?。。:)
復(fù)制代碼 代碼如下:
%@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
'析構(gòu)函數(shù),在使用 set nothing 釋放對象時,自動執(zhí)行
Private Sub Class_Terminate()
'response.Write "釋放對象 事件:Class_Terminatebr>"
call newsconnend()
end sub
'數(shù)據(jù)庫鏈接函數(shù)
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
'=========================================
'函數(shù)名 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 "rsbr>"
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
'----------------------------------------
'
'屬性寫 標(biāo)題
Public Property Let title(byval v)
title_p = v
End Property
'屬性讀 標(biāo)題
Public Property Get title()
title = title_p
End Property
'屬性寫 標(biāo)題ID
Public Property Let id(byval v)
id_p = v
End Property
'屬性讀 標(biāo)題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 數(shù)據(jù)庫 類 彭彭制作 QQ:76526211/title>
/head>
body>
%
dim news
set news = new NewsClass
call news.getrs("網(wǎng)站收藏",1,1,1,1)
response.write news.id " " news.title
set news = nothing
%>
/body>
/html>