0

I can't seem to figure out what's going on here:

EDIT: Let's try this... here's an outline of my code...

    Class form1
    Dim table1 as DataTable


    Sub refreshdata()
         table1.load() 'this puts data in table1
    End Sub

    Sub sub1 ()
         msgbox(table1.rows.count)  'this returns the number 15
     End Sub

    Sub combobox_closed (ByVal...) Handles ComboBox1.DropDownClosed
         msgbox(table1.rows.count)   'this returns the NullReferenceException

So what's the difference between the last two subs? Why can one access the table and not the other?

JH99
  • 3
  • 1
  • 3

1 Answers1

0

In the posted code. table1 is being declared as a local variable in one subroutine, and you are trying to access it from another subroutine. Make it a class scoped private variable instead to be able to access it from both routines.

Private table1 As DataTable = Nothing

jwatts1980
  • 6,943
  • 2
  • 25
  • 41
  • Sorry for all of the confusion, everyone. I figured it out. Turns out that DataTables are not very portable through routines, but DataSets work just fine. As in... table1.rows is inaccessible where dataset.table(0).rows is perfectly accessible by everyone. Go figure. – JH99 Aug 28 '14 at 17:10