Hi guys, I have a problem with a generic list, which consists of intances of a class i created. I am just amazed, each time I add a new object to the list, it overwrites the previous entries. Here is a code sample, i just can't beleive it. I am using visual studio 2010:
Dim translations As List(Of TranslatedValue) = New List(Of TranslatedValue)
If Session("ctlTexts") Is Nothing Then
Dim reader As IDataReader = DataAccessFunctions.db.GetDataReader("SELECT [ControlID], [ControlTextEN], [ControlTextDE], [ControlTextBG] FROM [dbo].[tbLanguage]", GetConnectionString)
While reader.Read()
Dim translationBulgarian As String = String.Empty
Dim translationGerman As String = String.Empty
Dim translationEnglish As String = String.Empty
Dim translationKey As String = String.Empty
Dim currentLanguageTranslation As String = String.Empty
If Not reader.IsDBNull(0) Then
translationKey = reader("ControlID")
End If
If Not reader.IsDBNull(1) Then
translationEnglish = reader("ControlTextEN")
End If
If Not reader.IsDBNull(2) Then
translationGerman = reader("ControlTextDE")
End If
If Not reader.IsDBNull(3) Then
translationBulgarian = reader("ControlTextBG")
End If
Select Case CurrentLanguage
Case Language.Bulgarian
currentLanguageTranslation = translationBulgarian
Exit Select
Case Language.English
currentLanguageTranslation = translationEnglish
Exit Select
Case Language.German
currentLanguageTranslation = translationGerman
Exit Select
End Select
translations.Add(New TranslatedValue(translationKey, translationEnglish, translationGerman, translationBulgarian, currentLanguageTranslation))
End While
reader.Close()
Session("ctlTexts") = translations