Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > code behind issues Run time errors help!

Reply
Thread Tools

code behind issues Run time errors help!

 
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      01-25-2005
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>
<aspataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="typID"
DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
DataTextField="TypName" HeaderText="Select Stone" runat="server" />
</Columns>
</aspataGrid></form>
</body>
</HTML>





 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      01-25-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
> <aspataGrid id="DataGrid1" style="" runat="server" >
> <Columns>
> <asp:HyperLinkColumn DataNavigateUrlField="typID"
> DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
> DataTextField="TypName" HeaderText="Select Stone" runat="server" />
> </Columns>
> </aspataGrid></form>
> </body>
> </HTML>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      01-25-2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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>
> > <aspataGrid id="DataGrid1" style="" runat="server" >
> > <Columns>
> > <asp:HyperLinkColumn DataNavigateUrlField="typID"
> > DataNavigateUrlFormatString="Slabs.aspx?TypID={0}"
> > DataTextField="TypName" HeaderText="Select Stone" runat="server" />
> > </Columns>
> > </aspataGrid></form>
> > </body>
> > </HTML>
> >
> >
> >
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run-time template list definition / Run-time variable type definition Pierre Yves C++ 2 01-10-2008 02:52 PM
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
Starting time and end time to fetch data from Code behind thomson ASP .Net 1 07-04-2006 12:11 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments