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

Home Posts Topics Members FAQ

code in class versus aspx page

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
Nov 18 '05 #1
5 1249
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

Nov 18 '05 #2
An ASPX Page IS a class. So, what you're saying is, if you move a single
line of code in one class that has no problems in that class where you have
it, to another class (where in that class, you don't mention), it throws an
exception. And you want to know why?

....

....

....

Step away from the computer. Slowly.

--
;-),
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"GaryB" <gb@nospam.co m> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
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

Nov 18 '05 #3
Okay, I'm trying to calm down from my incredulity, so that I can give you a
useful answer.

That single line of code is ONLY going to work in a method of a class which
has declared AND instantiated a DataSet named "dsGridRepo rt." In addition,
that DataSet must contain at least ONE table. If either the DataSet named in
that line of code doesn't exist, OR it has no tables in it, you will get the
exception you describe, as you are referencing an object (either
dsGridReport or its' table) that doesn't exist in that method or class.

You wouldn't take a carbeurator out of your car, stick it in another car of
another type, and expect it to work, would you?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"GaryB" <gb@nospam.co m> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
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

Nov 18 '05 #4
Wow, a flame from a weenie. It's been years.
Gary :)

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:O5******** ******@tk2msftn gp13.phx.gbl...
Okay, I'm trying to calm down from my incredulity, so that I can give you
a
useful answer.

That single line of code is ONLY going to work in a method of a class
which
has declared AND instantiated a DataSet named "dsGridRepo rt." In addition,
that DataSet must contain at least ONE table. If either the DataSet named
in
that line of code doesn't exist, OR it has no tables in it, you will get
the
exception you describe, as you are referencing an object (either
dsGridReport or its' table) that doesn't exist in that method or class.

You wouldn't take a carbeurator out of your car, stick it in another car
of
another type, and expect it to work, would you?

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"GaryB" <gb@nospam.co m> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
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


Nov 18 '05 #5
That wasn't a flame. It was an answer to your question. The last one you'll
get from this Weenie.

Luser. (THAT was a flame)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"GaryB" <gb@nospam.co m> wrote in message
news:uP******** ******@tk2msftn gp13.phx.gbl...
Wow, a flame from a weenie. It's been years.
Gary :)

"Kevin Spencer" <ks******@takem pis.com> wrote in message
news:O5******** ******@tk2msftn gp13.phx.gbl...
Okay, I'm trying to calm down from my incredulity, so that I can give you a
useful answer.

That single line of code is ONLY going to work in a method of a class
which
has declared AND instantiated a DataSet named "dsGridRepo rt." In addition, that DataSet must contain at least ONE table. If either the DataSet named in
that line of code doesn't exist, OR it has no tables in it, you will get
the
exception you describe, as you are referencing an object (either
dsGridReport or its' table) that doesn't exist in that method or class.

You wouldn't take a carbeurator out of your car, stick it in another car
of
another type, and expect it to work, would you?

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"GaryB" <gb@nospam.co m> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
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



Nov 18 '05 #6

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

Similar topics

9
2977
by: JohnSmith | last post by:
I suspect this is easy, but I have been stumped for a day trying to solve this.. I want to be able to have an unlimited number of aspx pages that all use the code in one class file. I want code in that class file to be able to read and write the controls on the aspx pages. For example, on all the aspx pages, I'll have a label named label1. From code in the class file, I want to be able to do something like label1.text = "hello world I...
6
2584
by: Earl Teigrob | last post by:
I am writing an application that dynamically loads user controls at run time based on user options. I would like to give my users the ability to build their own user controls and add them to my user control folder so that they can be selected and loaded at run time also. These new controls will need to have access to many of the classes with there properties and methods within the complied code. Is this possible? This seems to be the...
171
7806
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
17
2724
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
4
1216
by: bruce.1 | last post by:
It's my understanding that the next version of Visual Studio and ASP.NET will have the code-behind inline with the HTML, in the same file. It's also my understanding that Visual Studio will break-up the display so the .NET code will be shown on a screen separate from the HTML. What I'm wondering is how this will work when the file must be shared with and used by a front-end web designer, that's using Dreamweaver or whatever. Could they...
7
2244
by: Shapper | last post by:
Hello, When creating an ASP.NET/VB web site I place my code in a code behind page, i.e., aspx.vb. Sometimes I have functions which are common to all aspx files. Is it possible in page1.aspx to use page1.aspx.vb and also a common file named global.aspx.vb which will hold all the functions common to all aspx files in a web site.
29
3683
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form id="Form1" method="post" runat="server"> <%
3
4527
by: needin4mation | last post by:
Hi, I was trying to update some 1.1 code with 2005. I ran into problems, so I thought I'd just use notepad to make a minor change to the .cs file. When I run the .aspx file (and refresh), nothing happens. The changes aren't there. They are in the .aspx file, of course, but not the .aspx.cs file. In the bin file is theh .dll for the entire application. Does ASP.NET use the DLL or the codebehind? How can edit this code in notepad and...
2
4828
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
0
9705
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...
0
9575
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10564
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9134
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...
1
7609
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
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...
1
4288
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

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.