本文发表在 rolia.net 枫下论坛Imports System.Data.SqlClient
Public Class Class1
Private Sub AAA()
Using myConn As New SqlConnection("")
Dim myComm As New SqlCommand("Select ...", myConn)
myConn.Open()
Dim myDS As New DataSet
Dim sqlA As New SqlDataAdapter(myComm)
sqlA.Fill(myDS)
Dim i As Integer
Dim StrStart As String = "<ul><li>"
Dim strEnd As String = "</li></ul>"
Dim strhtml As String = StrStart
For i = 0 To myDS.Tables(0).Rows.Count - 1
If HasParent(CStr(myDS.Tables(0).Rows(i)("Parent")), myDS.Tables(0)) = False Then
strhtml += Recursion(CStr(myDS.Tables(0).Rows(i)("Parent")), myDS.Tables(0))
End If
Next
strhtml += strEnd
End Using
End Sub
Private Function HasParent(ByVal name As String, ByVal DT As DataTable) As Boolean
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If CStr(DT.Rows(i)("Child")) = name Then
Return True
End If
Next
Return False
End Function
Private Function HasChild(ByVal name As String, ByVal DT As DataTable) As Boolean
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If CStr(DT.Rows(i)("Parent")) = name Then
Return True
End If
Next
Return False
End Function
Private Function Recursion(ByVal Name As String, ByVal DT As DataTable) As String
Dim StrStart As String = "<ul><li>"
Dim strEnd As String = "</li></ul>"
Dim returnStr As String = String.Format("{0}{1}", StrStart, Name)
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If HasChild(Name, DT) Then
returnStr += Recursion(CStr(DT.Rows(i)("Parent")), DT)
End If
Next
Return returnStr + strEnd
End Function
End Class更多精彩文章及讨论,请光临枫下论坛 rolia.net
Public Class Class1
Private Sub AAA()
Using myConn As New SqlConnection("")
Dim myComm As New SqlCommand("Select ...", myConn)
myConn.Open()
Dim myDS As New DataSet
Dim sqlA As New SqlDataAdapter(myComm)
sqlA.Fill(myDS)
Dim i As Integer
Dim StrStart As String = "<ul><li>"
Dim strEnd As String = "</li></ul>"
Dim strhtml As String = StrStart
For i = 0 To myDS.Tables(0).Rows.Count - 1
If HasParent(CStr(myDS.Tables(0).Rows(i)("Parent")), myDS.Tables(0)) = False Then
strhtml += Recursion(CStr(myDS.Tables(0).Rows(i)("Parent")), myDS.Tables(0))
End If
Next
strhtml += strEnd
End Using
End Sub
Private Function HasParent(ByVal name As String, ByVal DT As DataTable) As Boolean
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If CStr(DT.Rows(i)("Child")) = name Then
Return True
End If
Next
Return False
End Function
Private Function HasChild(ByVal name As String, ByVal DT As DataTable) As Boolean
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If CStr(DT.Rows(i)("Parent")) = name Then
Return True
End If
Next
Return False
End Function
Private Function Recursion(ByVal Name As String, ByVal DT As DataTable) As String
Dim StrStart As String = "<ul><li>"
Dim strEnd As String = "</li></ul>"
Dim returnStr As String = String.Format("{0}{1}", StrStart, Name)
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
If HasChild(Name, DT) Then
returnStr += Recursion(CStr(DT.Rows(i)("Parent")), DT)
End If
Next
Return returnStr + strEnd
End Function
End Class更多精彩文章及讨论,请光临枫下论坛 rolia.net