Frog frog recommendation: asp implements tree structure selection from onlytiancai Blog
Keyword frog recommendation: asp achieves Tree Structure
Source
<! --
----------- [Test] Table Generation 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] (50) 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] [display Service] [3]
[9] [mainboard 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 WHERE t1.father _ id =" & Cint (parentID)
Rs. open SQL, strconn, 1, 1
Do While 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 While 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 ")
%>