473,498 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code behind issues Run time errors help!

Still new to code behind so i'm not sure what the problem is (i'm using
visualStudio.net for the first time) like my last question i'll bet this has
a quick answer. thanks
kes
here is the error: and please for give the excessive text

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 stack trace for more information about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.ExecuteReader()
Line 58: dGrdTyp.DataSource = dtrTyp
Line 59: dGrdTyp.DataBind()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\DamarStone\damarStone\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
damarStone.WebForm1.BindDataGrid() in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:58
damarStone.WebForm1.Page_Load(Object sender, EventArgs e) in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:35
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents dGrdTyp As System.Web.UI.WebControls.DataGrid
Public thsSitePath As String
#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 lblUser As System.Web.UI.WebControls.Label
Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents lnkToHome As System.Web.UI.WebControls.LinkButton

'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

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call Get_location()
Call BindDataGrid()
End Sub
Private Sub Get_location()
Dim thsUri As Uri
Dim thsHost As String
thsUri = Request.Url
thsHost = thsUri.Host
If (thsHost = "www.damarstone.com") Then
thsSitePath = "c:\websites\damar"
Else
thsSitePath = "e:\websites\damarstone\"
End If
lblUser.Text = thsSitePath
End Sub
Private Sub BindDataGrid()
Dim conTyp As OleDbConnection
Dim cmdSelectTyp As OleDbCommand
Dim dtrTyp As OleDbDataReader
lnkToHome.Text = "me"
conTyp = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA
Source=" & thsSitePath & "db\damarstone.mdb")
cmdSelectTyp = New OleDbCommand("SELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.ExecuteReader()
dGrdTyp.DataSource = dtrTyp
dGrdTyp.DataBind()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="typ.aspx.vb"
Inherits="damarStone.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblUser" runat="server" Font-Size="X-Small">Current
Action</asp:Label><br>
<asp:Label id="lblStatus" runat="server" Font-Size="XX-Small"
Width="240px">On the main stone types page</asp:Label><br>
<asp:LinkButton id="lnkToHome" runat="server">Home</asp:LinkButton><br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="typID"
DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
DataTextField="TypName" HeaderText="Select Stone" runat="server" />
</Columns>
</asp:DataGrid></form>
</body>
</HTML>

Nov 19 '05 #1
2 1346
dGrdTyp is a variable set to null. It has never been instantiated.

Typically this happens in asp.net when you have declared the variable in
your code behind page, but no corresponding element exists in the .aspx.

I see in your .aspx your grid is call DataGrid1, not dGrdType. So there you
go.

"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Still new to code behind so i'm not sure what the problem is (i'm using
visualStudio.net for the first time) like my last question i'll bet this
has
a quick answer. thanks
kes
here is the error: and please for give the excessive text

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 stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.ExecuteReader()
Line 58: dGrdTyp.DataSource = dtrTyp
Line 59: dGrdTyp.DataBind()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\DamarStone\damarStone\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
damarStone.WebForm1.BindDataGrid() in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:58
damarStone.WebForm1.Page_Load(Object sender, EventArgs e) in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:35
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents dGrdTyp As System.Web.UI.WebControls.DataGrid
Public thsSitePath As String
#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 lblUser As System.Web.UI.WebControls.Label
Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents lnkToHome As System.Web.UI.WebControls.LinkButton

'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

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call Get_location()
Call BindDataGrid()
End Sub
Private Sub Get_location()
Dim thsUri As Uri
Dim thsHost As String
thsUri = Request.Url
thsHost = thsUri.Host
If (thsHost = "www.damarstone.com") Then
thsSitePath = "c:\websites\damar"
Else
thsSitePath = "e:\websites\damarstone\"
End If
lblUser.Text = thsSitePath
End Sub
Private Sub BindDataGrid()
Dim conTyp As OleDbConnection
Dim cmdSelectTyp As OleDbCommand
Dim dtrTyp As OleDbDataReader
lnkToHome.Text = "me"
conTyp = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA
Source=" & thsSitePath & "db\damarstone.mdb")
cmdSelectTyp = New OleDbCommand("SELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.ExecuteReader()
dGrdTyp.DataSource = dtrTyp
dGrdTyp.DataBind()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="typ.aspx.vb"
Inherits="damarStone.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblUser" runat="server" Font-Size="X-Small">Current
Action</asp:Label><br>
<asp:Label id="lblStatus" runat="server" Font-Size="XX-Small"
Width="240px">On the main stone types page</asp:Label><br>
<asp:LinkButton id="lnkToHome" runat="server">Home</asp:LinkButton><br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="typID"
DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
DataTextField="TypName" HeaderText="Select Stone" runat="server" />
</Columns>
</asp:DataGrid></form>
</body>
</HTML>


Nov 19 '05 #2
I can't believe this!!!!
thanls
OU1!!!
kes

"Marina" wrote:
dGrdTyp is a variable set to null. It has never been instantiated.

Typically this happens in asp.net when you have declared the variable in
your code behind page, but no corresponding element exists in the .aspx.

I see in your .aspx your grid is call DataGrid1, not dGrdType. So there you
go.

"Kurt Schroeder" <Ku***********@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Still new to code behind so i'm not sure what the problem is (i'm using
visualStudio.net for the first time) like my last question i'll bet this
has
a quick answer. thanks
kes
here is the error: and please for give the excessive text

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 stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.ExecuteReader()
Line 58: dGrdTyp.DataSource = dtrTyp
Line 59: dGrdTyp.DataBind()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\DamarStone\damarStone\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
damarStone.WebForm1.BindDataGrid() in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:58
damarStone.WebForm1.Page_Load(Object sender, EventArgs e) in
E:\WebSites\DamarStone\damarStone\typ.aspx.vb:35
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.OleDb
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents dGrdTyp As System.Web.UI.WebControls.DataGrid
Public thsSitePath As String
#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 lblUser As System.Web.UI.WebControls.Label
Protected WithEvents lblStatus As System.Web.UI.WebControls.Label
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents lnkToHome As System.Web.UI.WebControls.LinkButton

'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

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Call Get_location()
Call BindDataGrid()
End Sub
Private Sub Get_location()
Dim thsUri As Uri
Dim thsHost As String
thsUri = Request.Url
thsHost = thsUri.Host
If (thsHost = "www.damarstone.com") Then
thsSitePath = "c:\websites\damar"
Else
thsSitePath = "e:\websites\damarstone\"
End If
lblUser.Text = thsSitePath
End Sub
Private Sub BindDataGrid()
Dim conTyp As OleDbConnection
Dim cmdSelectTyp As OleDbCommand
Dim dtrTyp As OleDbDataReader
lnkToHome.Text = "me"
conTyp = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; DATA
Source=" & thsSitePath & "db\damarstone.mdb")
cmdSelectTyp = New OleDbCommand("SELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.ExecuteReader()
dGrdTyp.DataSource = dtrTyp
dGrdTyp.DataBind()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="typ.aspx.vb"
Inherits="damarStone.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="lblUser" runat="server" Font-Size="X-Small">Current
Action</asp:Label><br>
<asp:Label id="lblStatus" runat="server" Font-Size="XX-Small"
Width="240px">On the main stone types page</asp:Label><br>
<asp:LinkButton id="lnkToHome" runat="server">Home</asp:LinkButton><br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="typID"
DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
DataTextField="TypName" HeaderText="Select Stone" runat="server" />
</Columns>
</asp:DataGrid></form>
</body>
</HTML>



Nov 19 '05 #3

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

Similar topics

242
13112
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
13
2024
by: AFKAFB | last post by:
Hi Sometimes when i edit previously saved VBA code e.g. To update field names etc the revised code does not work. Even if i copy and paste in a previous version it does not work. The only...
7
2412
by: Gene | last post by:
I have a number of aspx pages on which a single user control appears. All of the aspx pages and the user control make user of code-behind modules. I need for logic in the user control's code-behind...
171
7579
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)...
17
2668
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...
29
3641
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...
2
4803
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...
9
1763
by: chikkubhai | last post by:
Why is the result different for the following set of two code snippets Code without using this pointer #include <string> #include <iostream> using namespace std; struct X { private:
8
6320
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
0
7125
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,...
0
7004
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
7208
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...
1
6890
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...
0
7379
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...
0
4593
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...
0
3095
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...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.