Tree-type structure, tree structure <!--
-----------the [test] table to generate a script---------------
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Test] ') and OBJECTPROPERTY (ID, N ' isusertable ') = 1)
drop table [dbo]. [Test]
Go
CREATE TABLE [dbo]. [Test] (
[ID] [int] IDENTITY (1, 1) not NULL,
[Str_note] [nvarchar] (m) COLLATE chinese_prc_ci_as NULL,
[FATHER_ID] [INT] Null
) on [PRIMARY]
Go
-->
<!--
Test Data ********************
[ID] [Str_note] [FATHER_ID]
[1] [Computer Books] [0]
[2] [Software development] [1]
[3] [Hardware repair] [1]
[4] [ASP] [2]
[5] [PHP] [2]
[6] [JSP] [2]
[7] [HTML] [2]
[8] [Monitor Maintenance] [3]
[9] [Motherboard repair] [3]
[10] [Video card repair] [3]
[11] [VBS BASICS] [4]
[12] [HTML Basics] [4]
[13] [ADO Basics] [4]
[14] [Do statement] [11]
[15] [For statement] [11]
[16] [SELECT statement] [11]
***************************************************
-->
<%
Dim Strconn,conn,rs,sql
strconn= "Driver={sql Server};server=localhost;database=wawavote;uid=sa;pwd=sa;"
Dim I
I=0
Function Showtree (ParentID)
I=i+1
Dim RS
Set rs = Server.CreateObject ("ADODB.") RecordSet ")
sql= "SELECT ID, Str_note, father_id, (select Str_note from Test t2 WHERE t2.id = t1.father_id) as ParentName from Test T1 W Here t1.father_id= "&cint (ParentID)
Rs.Open sql,strconn,1,1
Do but not Rs. Eof
For J=1 to I
Response.Write ("---")
Next
Response.Write (RS (1) & "[" &rs (3) & "]<br>")
Showtree RS (0)
I=i-1
Rs. Movenext
Loop
Rs. Close:set rs=nothing
End Function
Sub showtable (table)
Dim RS
Set rs = Server.CreateObject ("ADODB.") RecordSet ")
Sql= "SELECT * from" &trim (table)
Rs.Open sql,strconn,1,1
For i=0 to Rs. Fields.count-1
Response.Write ("[" &rs.fields (i). name& "]")
Next
Response.Write ("<br>")
Do but not Rs. Eof
For i=0 to Rs. Fields.count-1
Response.Write ("[" &rs.fields (i). value& "]")
Next
Response.Write ("<br>")
Rs. MoveNext
Loop
Rs. Close:set rs=nothing
End Sub
Showtree (0)
Showtable ("Test")
%>
Author blog:http://blog.csdn.net/onlytiancai/