Frog recommendation: asp achieves tree structure

Source: Internet
Author: User
<! --
----------- [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 & "]")
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.