When you move it to a class I'm guessing you mean on separate from the
code behind class and that you are putting the line into a method of
some sort. Given this scenario you could end up with this problem for a
number of reasons:
First if you don't pass an instance of the dataset (dsGridReport) to the
class either as a property, a member lever variable, or a parameter of
the method it wouldn't be able to be seen by the line of code. This is
if the dataset is being created in the aspx page or its code behind.
Second would be if the dataset didn't have a table in it. This could be
caused if you were creating a data table and adding it to the table in
the codebehind, but are no longer doing that. In this instance you need
to make sure that you fully build the datatable and its column
definitions prior to trying to add a row to it. This can happen either
by filling the dataset from a datasource or by manually creating the
datatable and defining its columns.
These are the two ideas that spring to mind at this point. When you
string together the calls to objects like this it is hard to pinpoint
which one is causing the problem given limited information like this. To
get a better idea of what the actual issue is I'd set a break point on
the line and use the locals and or immediate/command window to find out
which object really has the issue then resolve where it would be created
and how that needs to be corrected for the line of code in question to
succeed.
Sorry I couldn't be more help.
Have A Better One!
John M Deal, MCP
Necessity Software
GaryB wrote:
The following line of code works fine in my code-behind file for an aspx
page:
Dim HeadingRow As DataRow = dsGridReport.Ta bles(0).NewRow( )
But when I transport that same code to a class and run it I get
"Object reference not set to an instance of an object"
Why?
Gary