下面的代码根据VS 2008中提供的用户名和密码获取数据。当我检查reader.FieldCount
时,它包含了它应该包含的所有字段。我遇到的问题是在results.Add
,它在文件的顶部定义为Dim results As List(Of String)
。当程序到达那一行时,抛出一个NullReferenceException,虽然我不知道为什么。
该程序旨在在MC9190-G上运行,并在设备上的代码中工作到那一点。我没有使用模拟器。代码直接部署到设备上进行测试。
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
connect()
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
reader.Read()
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
results.Add(temp)
i += 1
End While
reader.Close()
cn.Close()
comm.Dispose()
Return results
End If
MessageBox.Show("No results")
Return Nothing
End Function
您应该使用关键字New
:
Dim results As New List(Of String)