ASP无限分类数据库版
生活随笔
收集整理的這篇文章主要介紹了
ASP无限分类数据库版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
數據庫Access,字段:ClassID(主鍵),ParentClassID,ClassName,3個字段都是文本型。
<!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">
????<head>
????????<title>ASP無限分類數據庫版</title>
????????<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/>
????????<meta?name="Generator"?content="EditPlus">
????????<meta?name="Author"?content="Dicky;QQ:25941">
????????<meta?name="Keywords"?content="Dicky;QQ:25941;ASP無限分類數據庫版">
????????<meta?name="Description"?content="Dicky;QQ:25941;ASP無限分類數據庫版">
????</head>
????<body>
????????<%
????????Const?IsSql?=?0????'定義數據庫類型,1為SQL?Server,0為Access
????????Function?OpenConn(Conn)?????'打開數據庫連接
????????????Dim?ConnStr?
????????????If?IsSql?=?1?Then?'如果是SQL?Server數據庫?
????????????????'SQL?Server數據庫連接參數:用戶名、用戶密碼、數據庫名、連接名(本地用local,外地用IP)?
????????????????Dim?SqlUsername,SqlPassword,SqlDatabaseName,SqlLocalName?
????????????????SqlUsername?=?"sa"?
????????????????SqlPassword?=?""?
????????????????SqlDatabaseName?=?"TreeDb"?
????????????????SqlLocalName?=?"(local)"?
????????????????ConnStr?=?"Provider?=?Sqloledb;?User?ID?=?"?&?SqlUsername?&?";?Password?=?"?&?SqlPassword?&?";?Initial?Catalog?=?"?&?SqlDatabaseName?&?";?Data?Source?=?"?&?SqlLocalName?&?";"?
????????????Else??'如果是Access數據庫?
????????????????Dim?Db?
????????????????'第一次使用請修改本處數據庫地址并相應修改數據庫名稱,如將Dicky.mdb修改為Dicky.asp(防止惡意下載Access數據庫)?
????????????????Db?=?"TreeDB.mdb"?
????????????????ConnStr?=?"Provider?=?Microsoft.Jet.OLEDB.4.0;Data?Source?=?"?&?Server.MapPath(Db)
????????????End?If?
????????????On?Error?Resume?Next?
????????????Set?Conn?=?Server.CreateObject("ADODB.Connection")?
????????????Conn.Open?ConnStr?
????????????If?Err?Then?
????????'????????Err.Clear?
????????????????Set?Conn?=?Nothing?
????????????????Response.Write?"數據庫連接出錯,請檢查連接字串。"?
????????????????Response.End?
????????????End?If?
????????End?Function
????????Function?CloseConn(Conn)??'關閉數據庫連接?
????????????If?IsObject(Conn)?Then
????????????????Conn.Close?
????????????????Set?Conn?=?Nothing
????????????End?If
????????End?Function
????????Function?Echo(Str)?'輸出字符串并換行
????????????Response.Write?Str?&?VbCrlf
????????End?Function
????????Call?OpenConn(Conn)
????????'定義第一級分類
????????Sub?MainFl()
????????????Dim?Rs
????????????Set?Rs?=?Conn.Execute("SELECT?ClassID,ClassName?FROM?Class?WHERE?ParentClassID?IS?NULL")
????????????If?Not?Rs.Eof?Then
????????????????Do?While?Not?Rs.Eof
????????????????????Echo("<div><label?id="""?&?Trim(Rs("ClassID"))?&?""">+"?&?Trim(Rs("ClassName"))?&?"</label>")
????????????????????Call?Subfl(Rs("ClassID"),"|-")?'循環子級分類
????????????????????Echo("</div>")
????????????????Rs.MoveNext
????????????????If?Rs.Eof?Then?Exit?Do?'防上造成死循環
????????????????Loop
????????????End?If
????????????Set?Rs?=?Nothing
????????End?Sub
????????'定義子級分類
????????Sub?SubFl(FID,StrDis)
????????????Dim?Rs1
????????????Set?Rs1?=?Conn.Execute("SELECT?ClassID,ClassName?FROM?Class?WHERE?ParentClassID?=?'"?&?FID?&?"'")
????????????If?Not?Rs1.Eof?Then
????????????????Do?While?Not?Rs1.Eof
????????????????????Echo("????<div?id="""?&?Trim(Rs1("ClassID"))?&?""">"?&?StrDis?&?Trim(Rs1("ClassName"))?&?"</div>")
????????????????????Call?SubFl(Trim(Rs1("ClassID")),"|?"?&?Strdis)?'遞歸子級分類
????????????????Rs1.Movenext:Loop
????????????????If?Rs1.Eof?Then
????????????????????Rs1.Close
????????????????????Exit?Sub
????????????????End?If
????????????End?If
????????????Set?Rs1?=?Nothing
????????End?Sub
????????'最后直接調用MainFl()就行了
????????MainFl()
????????Call?CloseConn(Conn)%>
????</body>
</html>
<!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">
????<head>
????????<title>ASP無限分類數據庫版</title>
????????<meta?http-equiv="Content-Type"?content="text/html;?charset=gb2312"?/>
????????<meta?name="Generator"?content="EditPlus">
????????<meta?name="Author"?content="Dicky;QQ:25941">
????????<meta?name="Keywords"?content="Dicky;QQ:25941;ASP無限分類數據庫版">
????????<meta?name="Description"?content="Dicky;QQ:25941;ASP無限分類數據庫版">
????</head>
????<body>
????????<%
????????Const?IsSql?=?0????'定義數據庫類型,1為SQL?Server,0為Access
????????Function?OpenConn(Conn)?????'打開數據庫連接
????????????Dim?ConnStr?
????????????If?IsSql?=?1?Then?'如果是SQL?Server數據庫?
????????????????'SQL?Server數據庫連接參數:用戶名、用戶密碼、數據庫名、連接名(本地用local,外地用IP)?
????????????????Dim?SqlUsername,SqlPassword,SqlDatabaseName,SqlLocalName?
????????????????SqlUsername?=?"sa"?
????????????????SqlPassword?=?""?
????????????????SqlDatabaseName?=?"TreeDb"?
????????????????SqlLocalName?=?"(local)"?
????????????????ConnStr?=?"Provider?=?Sqloledb;?User?ID?=?"?&?SqlUsername?&?";?Password?=?"?&?SqlPassword?&?";?Initial?Catalog?=?"?&?SqlDatabaseName?&?";?Data?Source?=?"?&?SqlLocalName?&?";"?
????????????Else??'如果是Access數據庫?
????????????????Dim?Db?
????????????????'第一次使用請修改本處數據庫地址并相應修改數據庫名稱,如將Dicky.mdb修改為Dicky.asp(防止惡意下載Access數據庫)?
????????????????Db?=?"TreeDB.mdb"?
????????????????ConnStr?=?"Provider?=?Microsoft.Jet.OLEDB.4.0;Data?Source?=?"?&?Server.MapPath(Db)
????????????End?If?
????????????On?Error?Resume?Next?
????????????Set?Conn?=?Server.CreateObject("ADODB.Connection")?
????????????Conn.Open?ConnStr?
????????????If?Err?Then?
????????'????????Err.Clear?
????????????????Set?Conn?=?Nothing?
????????????????Response.Write?"數據庫連接出錯,請檢查連接字串。"?
????????????????Response.End?
????????????End?If?
????????End?Function
????????Function?CloseConn(Conn)??'關閉數據庫連接?
????????????If?IsObject(Conn)?Then
????????????????Conn.Close?
????????????????Set?Conn?=?Nothing
????????????End?If
????????End?Function
????????Function?Echo(Str)?'輸出字符串并換行
????????????Response.Write?Str?&?VbCrlf
????????End?Function
????????Call?OpenConn(Conn)
????????'定義第一級分類
????????Sub?MainFl()
????????????Dim?Rs
????????????Set?Rs?=?Conn.Execute("SELECT?ClassID,ClassName?FROM?Class?WHERE?ParentClassID?IS?NULL")
????????????If?Not?Rs.Eof?Then
????????????????Do?While?Not?Rs.Eof
????????????????????Echo("<div><label?id="""?&?Trim(Rs("ClassID"))?&?""">+"?&?Trim(Rs("ClassName"))?&?"</label>")
????????????????????Call?Subfl(Rs("ClassID"),"|-")?'循環子級分類
????????????????????Echo("</div>")
????????????????Rs.MoveNext
????????????????If?Rs.Eof?Then?Exit?Do?'防上造成死循環
????????????????Loop
????????????End?If
????????????Set?Rs?=?Nothing
????????End?Sub
????????'定義子級分類
????????Sub?SubFl(FID,StrDis)
????????????Dim?Rs1
????????????Set?Rs1?=?Conn.Execute("SELECT?ClassID,ClassName?FROM?Class?WHERE?ParentClassID?=?'"?&?FID?&?"'")
????????????If?Not?Rs1.Eof?Then
????????????????Do?While?Not?Rs1.Eof
????????????????????Echo("????<div?id="""?&?Trim(Rs1("ClassID"))?&?""">"?&?StrDis?&?Trim(Rs1("ClassName"))?&?"</div>")
????????????????????Call?SubFl(Trim(Rs1("ClassID")),"|?"?&?Strdis)?'遞歸子級分類
????????????????Rs1.Movenext:Loop
????????????????If?Rs1.Eof?Then
????????????????????Rs1.Close
????????????????????Exit?Sub
????????????????End?If
????????????End?If
????????????Set?Rs1?=?Nothing
????????End?Sub
????????'最后直接調用MainFl()就行了
????????MainFl()
????????Call?CloseConn(Conn)%>
????</body>
</html>
轉載于:https://www.cnblogs.com/Dicky/archive/2006/06/02/416235.html
總結
以上是生活随笔為你收集整理的ASP无限分类数据库版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaCV音视频开发宝典:vb8和vp
- 下一篇: 炒股段位说