G
Guest
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>
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>