Mitchell_Dude Mitchell_Dude - 24 days ago 4x
SQL Question

.NET CE 2.0 Data Access NullReferenceException when assigning DB fields to List(of T)

The code below grabs data based on a provided username and password in VS 2008. When I Check the

it contains all of the fields it should contain. The issue I am having is at
, which is defined at the top of the file as
Dim results As List(Of String)
. When the program reaches that line, a NullReferenceException is thrown, though I have no idea why.

The program is meant to run on an MC9190-G and works up to that point in the code on the device. I am not using an emulator. the code is deployed directly to the device for testing.

Public Function getUser(ByVal username As String, ByVal password As String)
Dim ecif As New EncryptionInfo
Dim ec As New Encryption(ecif.key, ecif.iv)
Dim pass_dec, temp As String
Dim i As Integer
query = "SELECT * FROM UserInfo WHERE Username = '" + username.ToString + "'"
comm = New SqlCommand(query, cn)
Dim reader As SqlDataReader = comm.ExecuteReader

If (reader.FieldCount <> 0) Then
i = 0
While (i < reader.FieldCount)
If (i = 1) Then
pass_dec = reader.GetString(i)
results.Add = ec.Decrypt(pass_dec)
Continue While
i += 1
End If
temp = reader.Item(i).ToString
i += 1
End While
Return results
End If

MessageBox.Show("No results")
Return Nothing

End Function


You should use the keyword New:

Dim results As New List(Of String)