天天看点

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涓?QL Server,0涓?ccess 
          Function  OpenConn(Conn)      ' ??寮??版??搴?杩???
              Dim  ConnStr 
             If  IsSql  =   1   Then   ' 濡?????SQL Server?版??搴?  
                  ' SQL Server?版??搴?杩??ュ?????ㄦ?峰?????ㄦ?峰???????版??搴?????杩??ュ??锛????扮??ocal锛?澶??扮??P锛?  
                  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(?叉?㈡?舵??涓?杞?ccess?版??搴?)  
                 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 

         ' ?????存?ヨ???ainFl()灏辫?浜? 
 
        MainFl()

         Call  CloseConn(Conn)% > 
     </ body > 
 </ html >