Collection.add

jfb1126

New member
Joined
Apr 30, 2007
Messages
2
Programming Experience
Beginner
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

Public Class WarrantyForms
Inherits MySQLBase

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

Public Sub LoadAllForms()
Dim strSQL As String
Dim dsData As New DataSet
Dim i As Int16
Dim blnResult As Boolean
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(dsData.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
End If
'***********************************************************************************************************
Catch ex As Exception
pvtLastException = ex
Finally
strSQL = Nothing
dsData = Nothing
i = Nothing
blnResult = Nothing
End Try
End Sub
 
Back
Top