humbleprogrammer
Programmer
Hello,
Can someone please help me out with the following error?
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Inetpub\ System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
------------------------------
Below is my public class code:
------------------------------
Imports System.Data.OleDb
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents grdItems As _
System.Web.UI.WebControls.DataGrid
'Declare a Connection object that is global
Dim objConnection As OleDbConnection
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub _
InitializeComponent()
End Sub
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
'Initialize the Connection object
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\pathtodatabase\Database\BabyShower.mdb"
' Bind the data the 1st time the page is built.
If Not (IsPostBack) Then
BindGrid("Status"
End If
End Sub
Sub BindGrid(ByVal strSortField As String)
'Declare objects.
Dim objDataSet As DataSet
Dim objDataAdapter As OleDbDataAdapter
'Set the SQL string.
objDataAdapter = New OleDbDataAdapter( _
"SELECT tblRegisteredItems.ID, tblRegisteredItems.ItemName, tblRegisteredItems.Description, tblRegisteredItems.SellingStores, tblRegisteredItems.Price, tblRegisteredItems.Status FROM tblRegisteredItems ORDER BY Status", objConnection)
'Initialize the DataSet object and fill it.
objDataSet = New DataSet()
objDataAdapter.Fill(objDataSet, "tblRegisteredItems"
'Declare a DataView object, populate it and sort the data in it.
Dim objDataview As DataView = _
objDataSet.Tables("tblRegisteredItems"
.DefaultView
objDataview.Sort = strSortField
'Bind the DataView object to the DataGrid control.
grdItems.DataSource = objDataview
grdItems.DataBind()
'Clean up.
objDataAdapter = Nothing
objDataSet = Nothing
objDataview = Nothing
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
'Clean up and unload connection.
objConnection = Nothing
End Sub
Private Sub grdItems_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles grdItems.SortCommand
'Bind the DataGrid using the sort column clicked.
BindGrid(e.SortExpression)
End Sub
End Class
Thanks in advance!
Can someone please help me out with the following error?
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Inetpub\ System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
------------------------------
Below is my public class code:
------------------------------
Imports System.Data.OleDb
Imports System.Data
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents grdItems As _
System.Web.UI.WebControls.DataGrid
'Declare a Connection object that is global
Dim objConnection As OleDbConnection
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub _
InitializeComponent()
End Sub
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
'Initialize the Connection object
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\pathtodatabase\Database\BabyShower.mdb"
' Bind the data the 1st time the page is built.
If Not (IsPostBack) Then
BindGrid("Status"
End If
End Sub
Sub BindGrid(ByVal strSortField As String)
'Declare objects.
Dim objDataSet As DataSet
Dim objDataAdapter As OleDbDataAdapter
'Set the SQL string.
objDataAdapter = New OleDbDataAdapter( _
"SELECT tblRegisteredItems.ID, tblRegisteredItems.ItemName, tblRegisteredItems.Description, tblRegisteredItems.SellingStores, tblRegisteredItems.Price, tblRegisteredItems.Status FROM tblRegisteredItems ORDER BY Status", objConnection)
'Initialize the DataSet object and fill it.
objDataSet = New DataSet()
objDataAdapter.Fill(objDataSet, "tblRegisteredItems"
'Declare a DataView object, populate it and sort the data in it.
Dim objDataview As DataView = _
objDataSet.Tables("tblRegisteredItems"
objDataview.Sort = strSortField
'Bind the DataView object to the DataGrid control.
grdItems.DataSource = objDataview
grdItems.DataBind()
'Clean up.
objDataAdapter = Nothing
objDataSet = Nothing
objDataview = Nothing
End Sub
Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
'Clean up and unload connection.
objConnection = Nothing
End Sub
Private Sub grdItems_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles grdItems.SortCommand
'Bind the DataGrid using the sort column clicked.
BindGrid(e.SortExpression)
End Sub
End Class
Thanks in advance!