Results 1 to 5 of 5

Thread: [RESOLVED] A DataSet / TreeView question

  1. #1

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Resolved [RESOLVED] A DataSet / TreeView question

    Fellas, at runtime, I populate a TreeView using a SQL query that populates a dataset.

    vb.net Code:
    1. Public Function GetRecorders(ByVal sqlString As String)
    2.         Dim result As Integer
    3.         ' -1 result means connection was not successful
    4.         Try
    5.             Dim _sql As String
    6.             _sql = sqlString
    7.             Dim connectionstring As String
    8.             connectionstring = "***PRIVATE***"
    9.             Dim cn As New SqlConnection(connectionstring)
    10.             da = New SqlDataAdapter(_sql, cn)
    11.             cn.Open()
    12.             Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
    13.             da.Fill(ds, "MyRecorders")
    14.             result = 0
    15.         Catch ex As Exception
    16.             result = -1
    17.         End Try
    18.         Return result
    19.     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!

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: A DataSet / TreeView question

    How about showing how you're trying to clear the objects out?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    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.

  4. #4

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    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!

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: A DataSet / TreeView question

    Trust me when I say I've seen weirder.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width