Null Reference Exception when run under machine name

S

Shannon

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
 
S

Supra

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
 
S

Shannon Albeke

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top