<
%
' 数据库连接
set conn = Server.CreateObject( " ADODB.Connection " )
conn.open " driver={SQLServer};server=chaiwei;DATABASE=chaiwei;UID=sa;PWD= "
' 打开所有父层数据
set rs = Server.CreateObject( " ADODB.Recordset " )
rs.Open " select*frompowerswherebelongidisnullorderbypowerid " ,conn, 1 , 3
' 层次数表态变量赋初值
format_i = 1
' 列表主程序段
do while not rs.eof
' 打印父层数据信息
response.write " <ahref='powerlist.asp?SelfID= " & rs( " powerid " ) & " &BelongID= " & rs( " belongid " ) & " '> " & rs( " powername " ) & " </a> "
response.write " <br> "
' 子程序调用,子层数据处理
Call ListSubPower(rs( " powerid " ))
rs.movenext
loop
' 关闭父层数据集
rs.close
set rs = nothing
' 子层数据处理子程序
Sub ListSubPower(id)
' 打开隶属于上层powerid的所有子层数据信息
set rs_sub = Server.CreateObject( " ADODB.Recordset " )
rs_sub.Open " select*frompowerswherebelongid= " & id & " orderbypowerid " ,conn, 1 , 3
' 列子层数据
do while not rs_sub.eof
' 层次数表态变量递进累加
format_i = format_i + 1
' 循环缩进格式控制,因为顶层与二层不需要缩进,所以从第三层开始引用此程序段
for i = format_i to 3 step - 1
response.write " | "
response.write " "
next
' 打印子层数据信息
response.write " |---- "
response.write " <ahref='powerlist.asp?SelfID= " & rs_sub( " powerid " ) & " &BelongID= " & rs_sub( " belongid " ) & " '> " & rs_sub( " powername " ) & " </a> "
response.write " <br> "
' 递归调用子程序本身,对子层数据进行逐渐处理
ListSubPower(rs_sub( " powerid " ))
rs_sub.movenext
loop
' 层次数表态变量递退累减
format_i = format_i - 1
' 关闭子层数据集
rs_sub.close
set rs_sub = nothing
EndSub
% >
' 数据库连接
set conn = Server.CreateObject( " ADODB.Connection " )
conn.open " driver={SQLServer};server=chaiwei;DATABASE=chaiwei;UID=sa;PWD= "
' 打开所有父层数据
set rs = Server.CreateObject( " ADODB.Recordset " )
rs.Open " select*frompowerswherebelongidisnullorderbypowerid " ,conn, 1 , 3
' 层次数表态变量赋初值
format_i = 1
' 列表主程序段
do while not rs.eof
' 打印父层数据信息
response.write " <ahref='powerlist.asp?SelfID= " & rs( " powerid " ) & " &BelongID= " & rs( " belongid " ) & " '> " & rs( " powername " ) & " </a> "
response.write " <br> "
' 子程序调用,子层数据处理
Call ListSubPower(rs( " powerid " ))
rs.movenext
loop
' 关闭父层数据集
rs.close
set rs = nothing
' 子层数据处理子程序
Sub ListSubPower(id)
' 打开隶属于上层powerid的所有子层数据信息
set rs_sub = Server.CreateObject( " ADODB.Recordset " )
rs_sub.Open " select*frompowerswherebelongid= " & id & " orderbypowerid " ,conn, 1 , 3
' 列子层数据
do while not rs_sub.eof
' 层次数表态变量递进累加
format_i = format_i + 1
' 循环缩进格式控制,因为顶层与二层不需要缩进,所以从第三层开始引用此程序段
for i = format_i to 3 step - 1
response.write " | "
response.write " "
next
' 打印子层数据信息
response.write " |---- "
response.write " <ahref='powerlist.asp?SelfID= " & rs_sub( " powerid " ) & " &BelongID= " & rs_sub( " belongid " ) & " '> " & rs_sub( " powername " ) & " </a> "
response.write " <br> "
' 递归调用子程序本身,对子层数据进行逐渐处理
ListSubPower(rs_sub( " powerid " ))
rs_sub.movenext
loop
' 层次数表态变量递退累减
format_i = format_i - 1
' 关闭子层数据集
rs_sub.close
set rs_sub = nothing
EndSub
% >