473,804 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object reference is required

DC
I have created the following abstract class:

public abstract class BaseC
{
protected int _ID;
protected string _name;

protected abstract DataTable GetData(int ID);
// intended to hit data access layer

protected static string GetValue(int ID)
{
DataTable DT = new DataTable();
DT = GetData(ID);

if (DT.Rows.Count == 1)
{
return DT.Rows[0]["name"].ToString();
}
else
{
return "";
}
}

}

I have also created the following derived class

public class DerivedC : BaseC
{

protected override DataTable GetFields(int ID)
{
DAL.List listDAL = new DAL.List();
listDAL.ID = ID
return listDAL.SelectO ne();
}
}

As you can see the SetFields method in BaseC will be
inherited and the GetFields method will be overridden. I
am getting the following error:

"An object reference for the nonstatic field, method, or
property 'NameSpace.Base C.GetFields(int )"

The GetFields(int) method is called from SetFieds(int) in
BaseC; however, the GetFields(int) method will be
overridden by the derived class so that the DAL can be
accessed.

Does anybody have any ideas on how to fix this?
Nov 15 '05 #1
2 3830
There is no Set Field method BaseC.
-------------------------
"Manish Agarwal"- <ma***********@ hotmail.com>

"DC" <donnie.carvaja l@transformyx_d ot_com> wrote in message
news:06******** *************** *****@phx.gbl.. .
I have created the following abstract class:

public abstract class BaseC
{
protected int _ID;
protected string _name;

protected abstract DataTable GetData(int ID);
// intended to hit data access layer

protected static string GetValue(int ID)
{
DataTable DT = new DataTable();
DT = GetData(ID);

if (DT.Rows.Count == 1)
{
return DT.Rows[0]["name"].ToString();
}
else
{
return "";
}
}

}

I have also created the following derived class

public class DerivedC : BaseC
{

protected override DataTable GetFields(int ID)
{
DAL.List listDAL = new DAL.List();
listDAL.ID = ID
return listDAL.SelectO ne();
}
}

As you can see the SetFields method in BaseC will be
inherited and the GetFields method will be overridden. I
am getting the following error:

"An object reference for the nonstatic field, method, or
property 'NameSpace.Base C.GetFields(int )"

The GetFields(int) method is called from SetFieds(int) in
BaseC; however, the GetFields(int) method will be
overridden by the derived class so that the DAL can be
accessed.

Does anybody have any ideas on how to fix this?

Nov 15 '05 #2
i assume you mean GetData() rather than GetFields(). The problem is that
GetValue() is static, ie a class method rather than an instance method; you
can't call the instance method GetData from a static context (there's no
"this").

"DC" <donnie.carvaja l@transformyx_d ot_com> wrote in message
news:06******** *************** *****@phx.gbl.. .
I have created the following abstract class:

public abstract class BaseC
{
protected int _ID;
protected string _name;

protected abstract DataTable GetData(int ID);
// intended to hit data access layer

protected static string GetValue(int ID)
{
DataTable DT = new DataTable();
DT = GetData(ID);

if (DT.Rows.Count == 1)
{
return DT.Rows[0]["name"].ToString();
}
else
{
return "";
}
}

}

I have also created the following derived class

public class DerivedC : BaseC
{

protected override DataTable GetFields(int ID)
{
DAL.List listDAL = new DAL.List();
listDAL.ID = ID
return listDAL.SelectO ne();
}
}

As you can see the SetFields method in BaseC will be
inherited and the GetFields method will be overridden. I
am getting the following error:

"An object reference for the nonstatic field, method, or
property 'NameSpace.Base C.GetFields(int )"

The GetFields(int) method is called from SetFieds(int) in
BaseC; however, the GetFields(int) method will be
overridden by the derived class so that the DAL can be
accessed.

Does anybody have any ideas on how to fix this?

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
3296
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline MFVec operator+(const MFVec& z1, const MFVec& z2) // Global function { MFVec res = z1; res += z2 return res; // WHY???
8
3197
by: Steve Neill | last post by:
Can anyone suggest how to create an arbitrary object at runtime WITHOUT using the deprecated eval() function. The eval() method works ok (see below), but is not ideal. function Client() { } Client.prototype.fullname = "John Smith"; var s = "Client"; eval("var o = new " + s + "();"); alert(o.fullname);
0
9784
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520" AutoPostBackOnNodeMove="false" DragAndDropEnabled="true" NodeEditingEnabled="False" KeyboardEnabled="true" CssClass="TreeView" NodeCssClass="TreeNode" SelectedNodeCssClass="SelectedTreeNode" HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
9
1652
by: Remulac | last post by:
Hello, I'm trying to get the value out of a dropdown list box and assign it to a variable. When I click on the list box, I invoke this line of code. I get the error, "Object reference not set to an instance of an object". The same list box is referenced successfully in the form load. Does anyone know what might cause this problem?
8
2478
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!! This is the error: biopsy.searchsubject.btnSubject_Click(Object Sender, EventArgs e) in C:\INetPub\WWWRoot\biopsy\searchsubject.aspx.vb:198 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
16
2905
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener will stay alive. Is this correct? If this is correct, I've got a problem. Let's say I've got an object Customer that has an PurchaseList (Collection) of Purchase objects. Now, these Purchase objects were pulled from a datasource Datasource. The...
12
2031
by: Belebele | last post by:
Suppose that a class A depends on class B because an object of class B is passed into A's constructor. See below: class B { ... }; class A { public: A(B const& b); ... };
21
1921
by: Andrew Ward | last post by:
Consider the following: #include <iostream> struct X { int x; X() { x = 6; } };
2
2661
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
4
2186
by: livmacca | last post by:
Hi, I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work: ==================ERROR================================== Object reference not set to an instance of an object. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10317
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.