2013-03-04 55 views
0

我在本代码的第三行中收到一个错误,因为“对象引用未设置为对象的实例” 。 可能的原因是什么?NullReferenceException vb.net

Dim table As New DataTable() 
Me.bindingSource1.DataSource = table 
Me.bindingSource1 = DataGridView1.DataSource 
table = Me.bindingSource1.DataSource 

我只需要知道的可能原因

回答

0

无论是 “我” 为空(在VB中为Nothing)或DataGridView1为空。原因可能在代码中的其他地方。使用调试器查明。

0

可能DataGridView1可能是nothingMe没有问题,因为执行超过了第二行而没有任何中断。检查DataGridView1是否为空。

  • 设置就行了3
  • 一个break pointbreak point罢工,按Ctrl+I(立即窗口)
  • 在该类型?DataGridView1
  • 并按ENTER,您会发现它是否为nothing