程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> Asp類 的數據庫領域

Asp類 的數據庫領域

編輯:關於ASP編程
奶奶的,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>



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved