Public Shared Function bodylist(ByVal topics As Integer, ByVal NavigationPanel As Panel)
Dim db As DB = New DB
Dim sSQL As String
Dim drDB As SqlClient.SqlDataReader
sSQL = "select * from Topic where AutoInc =" & topics
drDB = db.GetDataReader(sSQL)
If drDB.Read() Then
bodylist(drDB.Item("ParentID"), NavigationPanel)
Dim hyl As New HyperLink
NavigationPanel.Controls.Add(New LiteralControl("<td align = right WIDTH: 20%>>> "))
hyl.ID = drDB.Item("TopicName")
hyl.Text = drDB.Item("TopicName")
If IsDBNull(drDB.Item("TopicUrl")) Then
hyl.NavigateUrl = ""
Else
hyl.NavigateUrl = "javascript:hrefLocation('" & drDB.Item("TopicUrl") & "')"
End If hyl.ToolTip = IIf(IsDBNull(drDB.Item("TopicTitle")), "", drDB.Item("TopicTitle"))
NavigationPanel.Controls.Add(hyl)
NavigationPanel.Controls.Add(New LiteralControl("<td>"))
drDB.Close()
db.Dispose()
End If
drDB.Close()
db.Dispose()
End Function
db为数据库连接类
drDB为读数据库的方法。我这段代码用了递归,然后出现了个最大连接池的问题。
原因之所以在
是因为我在没有释放Connection ,而进行了递归,当中又连接Connection。
我尝试过多种方法,未果。
最后我尝试在后面用了db.dispose()释放了,但为什么还会不定时的报错。
有时候是不报错的。是不是.Net里就不允许用递归操作。
请问有什么办法能够解决吗?谢谢了。
Dim db As DB = New DB
Dim sSQL As String
Dim drDB As SqlClient.SqlDataReader
sSQL = "select * from Topic where AutoInc =" & topics
drDB = db.GetDataReader(sSQL)
If drDB.Read() Then
bodylist(drDB.Item("ParentID"), NavigationPanel)
Dim hyl As New HyperLink
NavigationPanel.Controls.Add(New LiteralControl("<td align = right WIDTH: 20%>>> "))
hyl.ID = drDB.Item("TopicName")
hyl.Text = drDB.Item("TopicName")
If IsDBNull(drDB.Item("TopicUrl")) Then
hyl.NavigateUrl = ""
Else
hyl.NavigateUrl = "javascript:hrefLocation('" & drDB.Item("TopicUrl") & "')"
End If hyl.ToolTip = IIf(IsDBNull(drDB.Item("TopicTitle")), "", drDB.Item("TopicTitle"))
NavigationPanel.Controls.Add(hyl)
NavigationPanel.Controls.Add(New LiteralControl("<td>"))
drDB.Close()
db.Dispose()
End If
drDB.Close()
db.Dispose()
End Function
db为数据库连接类
drDB为读数据库的方法。我这段代码用了递归,然后出现了个最大连接池的问题。
原因之所以在
是因为我在没有释放Connection ,而进行了递归,当中又连接Connection。
我尝试过多种方法,未果。
最后我尝试在后面用了db.dispose()释放了,但为什么还会不定时的报错。
有时候是不报错的。是不是.Net里就不允许用递归操作。
请问有什么办法能够解决吗?谢谢了。
eg
dim aa as string
dim i as integer
aa&i =drDB.item("xxx")
这样的话,aa&i会报错。
所以这种方案也搁浅了。但是效果的本身无法回避递归,只能用递归去实现他所以....
难道我还要改写到ASP?然后通过ASP在调用回来?
我是想做个树。但你说先放到变量里去,问题是我这些变量也是动态的啊。我该怎么去付值呢?
就是说我怎么去取道这些变量的名称呢?
Dim db As DB = New DB
Dim sSQL As String
Dim drDB As SqlClient.SqlDataReader
sSQL = "select * from Topic where AutoInc =" & topics
drDB = db.GetDataReader(sSQL)
If drDB.Read() Then
'''''''''''''''''''''''''''''''''''''
'注意这里
'''''''''''''''''''
dim myParentID = drDB.Item("ParentID") as string
dim myTopicName = drDB.Item("TopicName")
dim myTopicUrl = drDB.Item("TopicUrl")
'在这里关掉连接 drDB.Close()
db.Dispose()......''''''''''''''''''''''''''
'然后递归
bodylist(myParentID , NavigationPanel)
Dim hyl As New HyperLink
NavigationPanel.Controls.Add(New LiteralControl("<td align = right WIDTH: 20%>>> "))'''''''''''''''''''''
'在这里取变量 负值
''''''''''''''''''''''''
hyl.ID = myTopicName '还有这里 hyl.Text = drDB.Item("TopicName")
If IsDBNull(drDB.Item("TopicUrl")) Then
hyl.NavigateUrl = ""
Else
hyl.NavigateUrl = "javascript:hrefLocation('" & drDB.Item("TopicUrl") & "')"
End If hyl.ToolTip = IIf(IsDBNull(drDB.Item("TopicTitle")), "", drDB.Item("TopicTitle"))
NavigationPanel.Controls.Add(hyl)
NavigationPanel.Controls.Add(New LiteralControl("<td>"))
End If
drDB.Close()
db.Dispose()
End Function
用DataSet吧
用dataSet()
我递归了以后,会不会递归把dataSet()在内存中的虚拟表给覆盖掉啊。因为我深怕dataSet()经过递归了后把DataTable给覆盖掉,这样到后来我就白干了。再说如果成功的话,dataSet()递归,内存中一下子多了那么多表,不知道各算不各算。
挨,又是个问题。用cache?
我脑子也混了。
把数据都先放到DataSet中,然后,然后递归时,每次用DataView在DataSet中查询需要的记录处理
递归如果多的话,就完了。
内存要死掉了。
这个是我用dataSet()最担心的问题。