2014-03-26 71 views
-4
Dim id As Integer 
Dim tempIdList As List(Of Integer) 

If dr.Read() Then 
     Do 
     Dim loc As String 
     loc = dr("CurrentLocation").ToString() 
     id = dr("ID") 
     'tempIdList.Add(dr("ID")) 
     'tempIdList.Add(id) 
      If loc = comboFrom.Text Then 
        isContinue = True 
      End If 
     Loop While dr.Read 
End If 

我曾尝试那些注释掉的代码添加值。但我得到Object reference not set to an instance of an object
我试着添加一个断点,看起来这个列表没有得到一个值,只是Nothing,而id具有来自访问数据库的ID的值。列表不从数据库

出了什么问题?

+1

可能重复(http://stackoverflow.com/questions/4660142/what-is -a-的NullReferenceException和知识-DO-I-FIX-IT) – sloth

回答

2

tempIdList可能是Nothing。你必须与New关键字首先创建一个实例:什么是一个NullReferenceException,如何解决呢]的

Dim tempIdList As List(Of Integer) = New List(Of Integer)