0

i am getting an error as "object reference not set to an instance of an object" in the third line of this code. what are the possible reasons?

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

i just need to know the possible reasons

Daniel Imms
  • 43,032
  • 14
  • 130
  • 152
Shri
  • 834
  • 12
  • 35

2 Answers2

0

Either "Me" is null (nothing in VB) or DataGridView1 is null. The reasons for this are probably somewhere else in your code. Use the debugger to find out.

nvoigt
  • 61,531
  • 23
  • 73
  • 116
0

Possibly DataGridView1 might be nothing, There is no problem with Me because the execution crossed the second line with out any interrupt. check whether DataGridView1 is nothing or not.

  • Set a break point on the line 3.
  • while the break point strikes, press Ctrl+I (Immediate Window)
  • Type ?DataGridView1 in that.
  • And press ENTER, you will find whether it is nothing or not.
Rajaprabhu Aravindasamy
  • 63,064
  • 13
  • 90
  • 119