Results 1 to 2 of 2

Thread: Collection.add

  1. #1
    jfb1126 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2007
    Posts
    2
    Reputation
    0

    Question Collection.add

    I know this is probably something stupid and I just can't see it but...

    I have a collection class that has a LoadAllForms method that will loop through the Database and load the collection. the problem is when I envoke the add method it overwrites all items in the collection so when I get to the end of the table of 15 records, I have 15 instences of the last record in the table.

    any insight is appreciated!


    Imports System
    Imports System.Collections.Generic
    Imports System.Collections.ObjectModel

    PublicClass WarrantyForms
    Inherits MySQLBase

    Private pvtWarrantyForms AsNew Collection(Of WarrantyForm)
    Private pvtCurrentWarrantyForm As WarrantyForm

    PublicSub LoadAllForms()
    Dim strSQL AsString
    Dim dsData AsNew DataSet
    Dim i As Int16
    Dim blnResult AsBoolean
    Try
    strSQL = "SELECT * FROM WarrantyForm;"
    dsData = GetData(dsData, strSQL, pvtAccessKey)
    If dsData.Tables(0).Rows.Count > 0 Then
    For i = 0 To dsData.Tables(0).Rows.Count - 1
    blnResult = pvtCurrentWarrantyForm.GetWarrantyFormByDataRow(ds Data.Tables(0).Rows(i))
    MsgBox(pvtCurrentWarrantyForm.WarrantyFormCode) ' this works correctly
    If blnResult Then pvtWarrantyForms.Add(pvtCurrentWarrantyForm)
    MsgBox(pvtWarrantyForms.Item(0).WarrantyFormCode) ' this should show the first record every time, but doesn't
    Next i
    EndIf
    '************************************************* ************************************************** ********
    Catch ex As Exception
    pvtLastException = ex
    Finally
    strSQL = Nothing
    dsData = Nothing
    i = Nothing
    blnResult = Nothing
    EndTry
    EndSub

  2. #2
    jfb1126 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Apr 2007
    Posts
    2
    Reputation
    0

    Figured it out

    it appears that the item parameter for the add method is by reference not value.

Bookmarks

Posting Permissions

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