Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have some code in a listbox click event, it works the first time but accumalates in rows after further clicks. Any ideas why, thanks. Hope someone is out there.

    Dim sqlb As MySqlCommand = New MySqlCommand("SELECT * FROM TXMasters WHERE TXMasters.Barcode='" & ListBox1.SelectedItem & "'", con)

    DataAdapter2.Dispose()
    DataAdapter2.SelectCommand = sqlb
    DataAdapter2.Fill(ds2, "TXMasters")

    MaxRows2 = ds2.Tables(0).Rows.Count
    inc2 = -1

    ListBox1b.Items.Clear()

    For ty = 0 To MaxRows2 - 1
    ListBox1b.Items.Add(ds2.Tables(0).Rows(ty).Item(1) )
    Next

  2. #2
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found it. Adding the statement ds2.Clear cleared the data before refilling. Hope it helps somebody else.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by ZOR View Post
    I found it. Adding the statement ds2.Clear cleared the data before refilling. Hope it helps somebody else.

    The persistence of objects like that is something you have to get used to in .Net. If you dim the object in the same statement that populates it, you don't have to worry about it. But if you reuse a data object, you need to clear it.
    Charlotte

  4. #4
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks Charlotte, yes I will use DIM in the same statement. Have a nice weekend. Best Regards

Posting Permissions

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