473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
3 1704
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

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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Huskier | last post by:
Hi all: I want to pass a class-member function to pthread_create, and my code is in the following, but I don't know how to pass myobj.thread_function to pthread_create function. #include...
9
by: Jay Douglas | last post by:
Hello, I am needing to pass a class object (this) by reference to a method in a different class. When I do the following code I get the error (Cannot pass '<this>' as a ref or out argument because...
1
by: tony | last post by:
Hello! I just wonder if you out there have any your suggestion about this matter. I have a class in this class I have an ArrayList. In one instance method in this class I fill this ArrayList...
18
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning...
13
by: Francois Appert | last post by:
This post was originally in the C# Corner site, but their server is down. I'd like to see if this group can answer. I program in C++ and am learning C#. The issue is: why should anybody...
4
by: Lilith | last post by:
I have a form that invokes two other dialog forms for controlling the configuration of the program. The dialogs are invoked modally. Rather than pile up a large number of variables in the primary...
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.