By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,877 Members | 1,117 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,877 IT Pros & Developers. It's quick & easy.

How to pass data from a class data member to that class' display method?

P: n/a
Hi all,

I've got a class with a private DataSet member, and a void display()
method.

The display() method is *supposed* to take the DataSet for the class
(instance), new up a predefined for which has a DataGrid, slap the
DataSet onto the DataGrid, and set the form.visible to true.

I'm having trouble with a very early part of the process. The first
line of display() gives a runtime error:

int numRows = this.ClassDataSetMember.Tables["tbl"].Rows.Count;
Primary exception:
"An unhandled exception of type 'System.NullReferenceException'
occurred in ***.dll"

Inner exception:
"Additional information: Object reference not set to an instance of an
object."
This runtime error occurs when the main code calls the object.display()
method.

What am I doing wrong? I thought "this" was the way to say "that owns
the line of code currently running" (or something like that).

How do I get my object's display() method to make use of it's own
object's data?

I'm sure I'm confused over something really stupid - thanks for any
suggestions!

cdj

Oct 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Sorry if I duped a post, MS's web-based thingy has been uncooperative lately.

The "this" keyword references the current instance of a type. So for example
if you have a field in class-level scope, in your case, "ClassDataSetMember",
you could refer to it as this.ClassDataSetMember to disambiguate it from a
variable of the same name that is in a lower scope.

It seems from your description that you simply have not populated the field
with an instance of a DataSet. Here is a short example:

public class MyClass
{

public DataSet ClassDataSetMember;

public MyClass(DataSet myDataSet )
{
this.ClassDataSetMember = myDataSet;
}

}

Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
Oct 16 '06 #2

P: n/a

Peter wrote:
It seems from your description that you simply have not populated the field
with an instance of a DataSet.
hmm. So you're saying it looks like I'm making the right calls, there's
just nothing there to be called upon? lol - I'll look into it, and post
back if I'm convinced there *is* a DataSet to be referred to.

thanks for the reply!

cdj

Oct 17 '06 #3

P: n/a

Peter wrote:
It seems from your description that you simply have not populated the field
with an instance of a DataSet. Here is a short example:
You were right. (blush)

Oct 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.