473,387 Members | 1,683 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,387 software developers and data experts.

Null Reference Exception when run under machine name

I am having a very stange issue happen to my web application. I am
trying to develop a simple shopping cart. The code works perfectly
when I run the application under http://localhost/myapp. However, when
I try to run the same app under the machine name http://mymachine/myapp
I recieve a Null Reference Exception and the page crashes. I can't
figure out why this is happening. The Null Reference is referring to a
Session variable containing a dynamic DataTable which has the items the
user has chosen to purchase. The Store and the Shopping Cart are all
in 1 web form (only trying to sell t-shirts). Can anyone give me a
hint as to what may be happening. I am attaching the necessary code
snippets. Thanks in advance.

Dim objDT as DataTable = New DataTable
Dim objDR as DataRow
Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
makeCart()
End If

Function makeCart()
objDT = New System.Data.DataTable("Cart")
'create the columns to store the items in the shopping cart
Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs) 'this
handles the click event to add items to the cart.
objDT = Session("Cart")
For Each objDR In objDT.Rows 'this is the line which throws the
Null Reference error. After debugging I found that the Session("Cart")
= Nothing. As I mentioned above, this problem does not occur when run
under 'localhost'.
'do some stuff here
Next
End Sub

Jul 21 '05 #1
2 1891
the way i did in mastermind and ludo, chinese-checker, draughts, etc,
games using gdi in vb. i know errror problem when creating games. there
is nothing wrong with ur code. the only problem is coming from page_load
procedure..that is only way i know is coming from load event because i
used games programming .
this is how i do in games:

Dim PegHole As Image
Private Function CreatePegHoleImage() As Image
\\
\\
end Function
if i didn't add in form_load...i will get same error.

if i add in form_load( )
private sub form_load(byval........, ..........)
PegHole = Me.CreatePegHoleImage() <===== that is only way prevent error
end sub

but i haven't done yet datattable....but u can try this in below...

Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
objDR=me.makecart()
End If

regards


Shannon wrote:
I am having a very stange issue happen to my web application. I am
trying to develop a simple shopping cart. The code works perfectly
when I run the application under http://localhost/myapp. However, when
I try to run the same app under the machine name http://mymachine/myapp
I recieve a Null Reference Exception and the page crashes. I can't
figure out why this is happening. The Null Reference is referring to a
Session variable containing a dynamic DataTable which has the items the
user has chosen to purchase. The Store and the Shopping Cart are all
in 1 web form (only trying to sell t-shirts). Can anyone give me a
hint as to what may be happening. I am attaching the necessary code
snippets. Thanks in advance.

Dim objDT as DataTable = New DataTable
Dim objDR as DataRow
Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
makeCart()
End If

Function makeCart()
objDT = New System.Data.DataTable("Cart")
'create the columns to store the items in the shopping cart
Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs) 'this
handles the click event to add items to the cart.
objDT = Session("Cart")
For Each objDR In objDT.Rows 'this is the line which throws the
Null Reference error. After debugging I found that the Session("Cart")
= Nothing. As I mentioned above, this problem does not occur when run
under 'localhost'.
'do some stuff here
Next
End Sub


Jul 21 '05 #2

Thanks for the tip, but unfortunately the problem still exists. I will
try to work out some variations of how the variable is loaded based upon
your comments. If you have further insight, please let me know.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3

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

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
7
by: odonel | last post by:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: here is my code: HttpCookie cookie = Request.Cookies;
4
by: rrober07 | last post by:
Hello, My Setup is I have a Web Server machine(Devweb01), Database SQL Machine(Devsql01), a Client Machine(local machine) I have configured the SQL machine as follows: 1) Added local Aspnet...
16
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project -...
2
by: Shannon | last post by:
I am having a very stange issue happen to my web application. I am trying to develop a simple shopping cart. The code works perfectly when I run the application under http://localhost/myapp. ...
1
by: connor7777 | last post by:
Hi guys: We've been weeding out errors off of a java->c# project and have managed to redeem most of our code with the exception of one bug that we for some reason cannot pin down. The following...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
1
by: vaibhavchavan | last post by:
Hi I am doing application for signing of soap message with digital certificate . I am using WSE 2.0 I worte the the simple webservice & deployed it on in our server machine . To make it...
2
by: Febria | last post by:
Dear, all... I have some problem with my application. I used UltraWebGrid component in my web application. Unfortunately, when I tried to run the web, the error page displayed: The located...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.