Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Reference Error

Status
Not open for further replies.

humbleprogrammer

Programmer
Oct 30, 2002
315
US
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(&quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\pathtodatabase\Database\BabyShower.mdb&quot;)
' Bind the data the 1st time the page is built.
If Not (IsPostBack) Then
BindGrid(&quot;Status&quot;)
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( _
&quot;SELECT tblRegisteredItems.ID, tblRegisteredItems.ItemName, tblRegisteredItems.Description, tblRegisteredItems.SellingStores, tblRegisteredItems.Price, tblRegisteredItems.Status FROM tblRegisteredItems ORDER BY Status&quot;, objConnection)

'Initialize the DataSet object and fill it.
objDataSet = New DataSet()
objDataAdapter.Fill(objDataSet, &quot;tblRegisteredItems&quot;)

'Declare a DataView object, populate it and sort the data in it.
Dim objDataview As DataView = _
objDataSet.Tables(&quot;tblRegisteredItems&quot;).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!
 
Thanks for your reply. I figured out that there was some kind of lock on the .dll file in the bin folder so I think it wasn't able to compile properly. So I started a new project, copied my previous source into it and now it's working.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top