[RESOLVED] A DataSet / TreeView question
Fellas, at runtime, I populate a TreeView using a SQL query that populates a dataset.
vb.net Code:
Public Function GetRecorders(ByVal sqlString As String)
Dim result As Integer
' -1 result means connection was not successful
Try
Dim _sql As String
_sql = sqlString
Dim connectionstring As String
connectionstring = "***PRIVATE***"
Dim cn As New SqlConnection(connectionstring)
da = New SqlDataAdapter(_sql, cn)
cn.Open()
Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "MyRecorders")
result = 0
Catch ex As Exception
result = -1
End Try
Return result
End Function
I have a "Refresh" Button on my form that I want to clear all nodes in my TreeView and then re-populate it just like I do at Form Load. I have tried clearing my TreeView, clearing the dataset, clearing the dataset's Tables.. and nothing seems to work.. it keeps add appending the new list to the TreeView instead of clearing it.
Can you help me figure out the correct way to fill a dataset at Load time and be able to re-use that one dataset throughout the life of the program and be able to clera it, refill it, etc.?
Thanks!
Re: A DataSet / TreeView question
How about showing how you're trying to clear the objects out?
-tg
Re: A DataSet / TreeView question
well I tried various things at the start of the Try Block such as:
ds.Clear
ds.Tables.Clear
'Clear the List if anything is there
Me.MyRecordersTree.Nodes.Clear()
none worked.
Re: A DataSet / TreeView question
wow ummm.. i just tried it again with:
ds.Tables.Clear()
at the beginning of the Try block (JUST LIKE I HAD IT BEFORE!!) and now it's working??!!! weeeeird!
Re: A DataSet / TreeView question
Trust me when I say I've seen weirder.
-tg