Hi i have the following function:
Public Shared Function GetAbrechnung() As List(Of WochenBPlan)
Dim wbp = New WochenBPlan
Dim allBookings As List(Of WochenBPlan) = New List(Of WochenBPlan)
Dim strSQL As String = "SELECT DISTINCT d.ABTEILUNG, d.BEMERKUNG, d.BESTUHLUNG, d.RAUMID, d.ID, d.PERSONENZAHL, d.ADRESSE + ', ' + d.RAUMBEZEICHNUNG AS RAUMBEZEICHNUNG, d.THEMA, p.VN + ' ' + p.NN AS NAME, CONVERT (char(5), d.VON, 108) + ' - ' + CONVERT (char(5), d.BIS, 108) AS ZEIT, p.TEL FROM VIEW_RAUMBUCHUNG_DISPO AS d INNER JOIN PERSONAL AS p ON d.PERSONAL_ID = p.ID WHERE THEMA = 'EVENT'"
Dim objRS As SqlDataReader
objRS = SQLrunReaderWB(strSQL)
If objRS.HasRows Then
While objRS.Read()
wbp.Raum = objRS("RAUMBEZEICHNUNG")
wbp.Zeit = objRS("ZEIT")
If Not IsDBNull(objRS("ABTEILUNG")) Then
wbp.Bereich = objRS("ABTEILUNG")
End If
If Not IsDBNull(objRS("THEMA")) Then
wbp.Thema = objRS("THEMA")
End If
If Not IsDBNull(objRS("NAME")) Then
wbp.Mieter = objRS("NAME")
End If
If Not IsDBNull(objRS("TEL")) Then
wbp.Mieter_Tel = objRS("TEL")
End If
wbp.Personen = objRS("PERSONENZAHL")
wbp.Bestuhlung = objRS("BESTUHLUNG")
If Not IsDBNull(objRS("BEMERKUNG")) Then
wbp.Bemerkung = objRS("BEMERKUNG")
End If
allBookings.Add(wbp)
End While
Else
End If
ConnWB.Close()
Return allBookings
End Function
My Problem is that my List which i have generated is just returning the last value. What iam doing wrong? Can someone help?
You need to declare your scope object inside the loop. If you do not, you will get only the reference of the same object, changing it and therefore will be the last modification that will contain the list.
try something like this: