473,325 Members | 2,872 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,325 software developers and data experts.

Weird issue with System.NullReferenceException

I am having a very strange issue with my asp.net application. I have
created a datagrid which dynamically gets populated from a person
choosing a value from a dropdown list and entering a quantity into a
text box (a simple version of a shopping cart). When I run/debug the
web page using the localhost in the page URL
(http://localhost/mypage.aspx), the datagrid updates properly when a
command button is clicked and all is well. However, when I run the web
page using the machinename (http://mymachine/mypage.aspx) I recieve the
error "Object Reference not Set...System.NullReferenceException" when I
click the command button to update the datagrid with new values. Does
anyone have a solution as to why it works as localhost but does not as
machinename? And does anyone have a solution? Thanks in advance.
Shannon

Jul 21 '05 #1
2 1902
I think it would be helpful if you posted the code behind up.

Ciaran

"Shannon" <sh************@state.co.us> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com...
I am having a very strange issue with my asp.net application. I have
created a datagrid which dynamically gets populated from a person
choosing a value from a dropdown list and entering a quantity into a
text box (a simple version of a shopping cart). When I run/debug the
web page using the localhost in the page URL
(http://localhost/mypage.aspx), the datagrid updates properly when a
command button is clicked and all is well. However, when I run the web
page using the machinename (http://mymachine/mypage.aspx) I recieve the
error "Object Reference not Set...System.NullReferenceException" when I
click the command button to update the datagrid with new values. Does
anyone have a solution as to why it works as localhost but does not as
machinename? And does anyone have a solution? Thanks in advance.
Shannon

Jul 21 '05 #2
Here is the requested code behind.

Imports System.Data.SqlClient
Public Class merchandise
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents lblNavBar As System.Web.UI.WebControls.Label
Protected WithEvents lblMerchandise As
System.Web.UI.WebControls.Label
Protected WithEvents merTXT1 As System.Web.UI.WebControls.Label
Protected WithEvents merTXT2 As System.Web.UI.WebControls.Label
Protected WithEvents ddProducts As
System.Web.UI.WebControls.DropDownList
Protected WithEvents txtQty As System.Web.UI.WebControls.TextBox
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents btnCart As
System.Web.UI.WebControls.LinkButton
Protected WithEvents dgCart As System.Web.UI.WebControls.DataGrid
Protected WithEvents lblTotal As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region
Public objDT As System.Data.DataTable
Public objDR As System.Data.DataRow

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim dbConn As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectRWData"))

'retrieve the data from the database for the List Box
Content
Dim daMerchandise As New SqlDataAdapter("SELECT prodTYPE,
prodCOST, prodTYPE + ' - $' + CAST(prodCOST AS char(5)) AS prodLIST
FROM tblProducts", dbConn)

'fill the dataset
Dim dsmerchandise As New DataSet
daMerchandise.Fill(dsMerchandise, "tblProducts")

'fill the list box with the values.
ddProducts.DataSource = dsmerchandise.Tables("tblProducts")
ddProducts.DataTextField = "prodLIST"
ddProducts.DataValueField = "prodCOST"
ddProducts.DataBind()

'create the dynamic shopping cart table
makeCart()
End If
End Sub

Function makeCart()

objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1

objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))

Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs)
objDT = Session("Cart")

Dim Product = ddProducts.SelectedItem.Text

objDR = objDT.NewRow 'this is the line creating the error when
run under machinename
objDR("Quantity") = txtQty.Text
objDR("Product") = ddProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddProducts.SelectedItem.Value)
objDT.Rows.Add(objDR)
Session("Cart") = objDT

dgCart.DataSource = objDT
dgCart.DataBind()

End Sub
End Class

Jul 21 '05 #3

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

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: Deutsche Dogge | last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically on the popup event of the menuitem containing the container of the menuitems i wanna add (tools -> external -> {list of...
2
by: Nicholas | last post by:
I have this class that provides a disk-based queue for storing various items. As items are queued the event delegate is called and the consumer dequeues the object and processes it. This seems to...
3
by: Me | last post by:
I'm getting a NullReferenceException in Unknown Module when I follow the below steps to create a simple NotifyIcon app that creates the context menu on the fly(see a little analysis after the...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
3
by: Celebrate | last post by:
My application works fine when I run it locally but when I transfer it to our NEW Windows 2003 Web Edition server, I get a strange error. I've isolated the problem to when I issue a...
2
by: Shannon | last post by:
I am having a very strange issue with my asp.net application. I have created a datagrid which dynamically gets populated from a person choosing a value from a dropdown list and entering a quantity...
2
by: Stephan Zaubzer | last post by:
Hi all, I encountered a problem with NumericUpDown yesterday and managed to reproduce the error with a very easy examle. I have a Windows Application with only one Form, which contains only one...
1
by: Tim_Mac | last post by:
hi, i am encountering a sporadic exception using crystal reports that is causing me grief, I can't 'handle' it... my code is loading a typed report, and loading a DataSet to it. unfortunately...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.