Reputation: 6555
I'm using the following code to attempt to import a CSV file. However it is just saving the last object of Fact
rather than saving each of the objects that were built.
Do While Not sr.EndOfStream
Dim aFact as Fact
Dim mArray = sr.ReadLine().Split(",")
aFact.Name = mArray(0)
aFact.Value = mArray(1)
db.Facts.Add(aFact)
End
db.SaveChanges()
Upvotes: 0
Views: 44
Reputation: 359
Just use a list where you save the object
Dim factList As New List(Of Fact) ' add the list
Do While Not sr.EndOfStream
Dim aFact as Fact
Dim mArray = sr.ReadLine().Split(",")
aFact.Name = mArray(0)
aFact.Value = mArray(1)
factList.Add(aFact) ' put fact object in list
End
Upvotes: 1