473,624 Members | 2,278 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.ne t 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.Ex ecuteReader()
Line 58: dGrdTyp.DataSou rce = dtrTyp
Line 59: dGrdTyp.DataBin d()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
damarStone.WebF orm1.BindDataGr id() in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :58
damarStone.WebF orm1.Page_Load( Object sender, EventArgs e) in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :35
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.Ole Db
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls
Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents dGrdTyp As System.Web.UI.W ebControls.Data Grid
Public thsSitePath As String
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents lblUser As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblStatus As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents lnkToHome As System.Web.UI.W ebControls.Link Button

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

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

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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\da mar"
Else
thsSitePath = "e:\websites\da marstone\"
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=Micr osoft.Jet.OLEDB .4.0;DATA
Source=" & thsSitePath & "db\damarstone. mdb")
cmdSelectTyp = New OleDbCommand("S ELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.Ex ecuteReader()
dGrdTyp.DataSou rce = dtrTyp
dGrdTyp.DataBin d()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="typ .aspx.vb"
Inherits="damar Stone.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</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">O n the main stone types page</asp:Label><br>
<asp:LinkButt on id="lnkToHome" runat="server"> Home</asp:LinkButton> <br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkC olumn DataNavigateUrl Field="typID"
DataNavigateUrl FormatString="S labs.aspx?TypID ={0}"
DataTextField=" TypName" HeaderText="Sel ect Stone" runat="server" />
</Columns>
</asp:DataGrid></form>
</body>
</HTML>

Nov 19 '05 #1
2 1353
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.mic rosoft.com> wrote in message
news:B4******** *************** ***********@mic rosoft.com...
Still new to code behind so i'm not sure what the problem is (i'm using
visualStudio.ne t 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.Ex ecuteReader()
Line 58: dGrdTyp.DataSou rce = dtrTyp
Line 59: dGrdTyp.DataBin d()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
damarStone.WebF orm1.BindDataGr id() in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :58
damarStone.WebF orm1.Page_Load( Object sender, EventArgs e) in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :35
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.Ole Db
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls
Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents dGrdTyp As System.Web.UI.W ebControls.Data Grid
Public thsSitePath As String
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents lblUser As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblStatus As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents lnkToHome As System.Web.UI.W ebControls.Link Button

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

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

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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\da mar"
Else
thsSitePath = "e:\websites\da marstone\"
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=Micr osoft.Jet.OLEDB .4.0;DATA
Source=" & thsSitePath & "db\damarstone. mdb")
cmdSelectTyp = New OleDbCommand("S ELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.Ex ecuteReader()
dGrdTyp.DataSou rce = dtrTyp
dGrdTyp.DataBin d()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="typ .aspx.vb"
Inherits="damar Stone.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</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">O n the main stone types page</asp:Label><br>
<asp:LinkButt on id="lnkToHome" runat="server"> Home</asp:LinkButton> <br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkC olumn DataNavigateUrl Field="typID"
DataNavigateUrl FormatString="S labs.aspx?TypID ={0}"
DataTextField=" TypName" HeaderText="Sel ect 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.mic rosoft.com> wrote in message
news:B4******** *************** ***********@mic rosoft.com...
Still new to code behind so i'm not sure what the problem is (i'm using
visualStudio.ne t 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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:
Line 56: conTyp.Open()
Line 57: dtrTyp = cmdSelectTyp.Ex ecuteReader()
Line 58: dGrdTyp.DataSou rce = dtrTyp
Line 59: dGrdTyp.DataBin d()
Line 60: dtrTyp.Close()

Source File: E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb Line: 58
Stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
damarStone.WebF orm1.BindDataGr id() in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :58
damarStone.WebF orm1.Page_Load( Object sender, EventArgs e) in
E:\WebSites\Dam arStone\damarSt one\typ.aspx.vb :35
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +67
System.Web.UI.C ontrol.LoadRecu rsive() +35
System.Web.UI.P age.ProcessRequ estMain() +750
********
and the pages:
********
typ.aspx.vb:
Imports System.Data.Ole Db
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.UI.H tmlControls
Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents dGrdTyp As System.Web.UI.W ebControls.Data Grid
Public thsSitePath As String
#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()

End Sub
Protected WithEvents lblUser As System.Web.UI.W ebControls.Labe l
Protected WithEvents lblStatus As System.Web.UI.W ebControls.Labe l
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid
Protected WithEvents lnkToHome As System.Web.UI.W ebControls.Link Button

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

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

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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\da mar"
Else
thsSitePath = "e:\websites\da marstone\"
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=Micr osoft.Jet.OLEDB .4.0;DATA
Source=" & thsSitePath & "db\damarstone. mdb")
cmdSelectTyp = New OleDbCommand("S ELECT t.typID, t.typName,
t.typeDesc FROM typ t ORDER BY t.typName;", conTyp)
conTyp.Open()
dtrTyp = cmdSelectTyp.Ex ecuteReader()
dGrdTyp.DataSou rce = dtrTyp
dGrdTyp.DataBin d()
dtrTyp.Close()
conTyp.Close()
End Sub
End Class
***********
typ.aspx:
<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="typ .aspx.vb"
Inherits="damar Stone.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
</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">O n the main stone types page</asp:Label><br>
<asp:LinkButt on id="lnkToHome" runat="server"> Home</asp:LinkButton> <br>
<asp:DataGrid id="DataGrid1" style="" runat="server" >
<Columns>
<asp:HyperLinkC olumn DataNavigateUrl Field="typID"
DataNavigateUrl FormatString="S labs.aspx?TypID ={0}"
DataTextField=" TypName" HeaderText="Sel ect 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
13323
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 comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
13
2037
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 solution seems to be to delete the existing code, re-type ir word for word and hey presto it works. Of course you might think typo or something but its like Access seems
7
2416
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 to read the current value of a variable in the hosting aspx page's code-behind. How is this accomplished? Thanks.
171
7687
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
17
2691
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
29
3667
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 id="Form1" method="post" runat="server"> <%
2
4814
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 required: <%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %> Assuming that the ASPX page doesn't use a code-behind, I can access the properties, events etc. of the user control in the ASPX page in this way (assume that the ASPX page...
9
1772
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
6325
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. Just to get it to work, I hard-coded the username and password of a SQL Server account in the connectionstring in web.config. Once I confirmed that this worked on the web server, I wanted to remove the hard-coded password from web.config, so I...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1793
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.