Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.

This is the error i am getting, it says to review the stack trace. Here is the stack trace with code from my vb file below.

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Manager.bindData(String sortExpression) +52
Manager.Page_Load(Object sender, EventArgs e) +13
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +750

Private Sub Page_Load(ByVal sender As System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
If not ispostback then
bindData("BugFind.BugID")
End If
end sub

Private Sub bindData(ByVal sortExpression as String)
Dim uEmail as string
uEmail = Session("Email").ToString()
dim conn as OleDbConnection
dim adapter as OleDbDataAdapter
dim mydataset as DataSet
dim connstring, query as string

Try
connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="& server.mappath("Database.mdb")
conn = new OleDbConnection(connstring)
conn.Open()
query = "Select [Products].[ProductName], [BugFind].[FeatureName], [BugFind].[FinderEmail], [BugFind].[BuildNumber], [BugFind].[MajorReleaseNumber], [BugFind].[MinorReleaseNumber], [BugFind].[FindDate], [BugFind].[BugID], [BugFind].[FindTime] FROM [BugFind], [Products] where [BugFind].[ProductID] = [Products].[Product ID] and [Products].[ManagerEmail] = ('" & uEmail & "') ORDER BY " & sortExpression

adapter = new OleDbDataAdapter(query, conn)
mydataset = new dataset
adapter.Fill(mydataset)
BugsAssigned.DataKeyField = "BugID"
BugsAssigned.DataSource = mydataset
BugsAssigned.DataBind()

Finally
If (not isnothing(conn)) then
conn.close()
End if
End Try
End Sub

I really need help, because this is happening on another page of mine also and its head wrecking. I can't fix it.couple things to check...

::uEmail = Session("Email").ToString()

if Email does not exist in your session, your uEmail will be null/nothing

::BugsAssigned.DataKeyField = "BugID"

What is BugsAssigned, and does it exist (i.e. was an instance created...)?
Hey cheers for the reply. I have changed the uEmail string to a hard coded email address fopr the time being. You brought to my attention:

BugsAssigned.DataKeyField = "BugID"

What is BugsAssigned, and does it exist (i.e. was an instance created...)?

BugAssigned was an incorrect id for my DataGrid. It should be BugTable, but when i renamed it to BugTable it gave me this error:

Name 'BugTable' is not declared.

mydataset = new dataset

Line 46: adapter.Fill(mydataset)
Line 47: BugTable.DataKeyField = "BugID"
Line 48: BugTable.DataSource = mydataset
Line 49: BugTable.DataBind()
Hey cheers for the reply. I have changed the uEmail string to a hard coded email address fopr the time being. You brought to my attention:

BugsAssigned.DataKeyField = "BugID"

What is BugsAssigned, and does it exist (i.e. was an instance created...)?

BugAssigned was an incorrect id for my DataGrid. It should be BugTable, but when i renamed it to BugTable it gave me this error:

Name 'BugTable' is not declared.

mydataset = new dataset

Line 46: adapter.Fill(mydataset)
Line 47: BugTable.DataKeyField = "BugID"
Line 48: BugTable.DataSource = mydataset
Line 49: BugTable.DataBind()
Well, where did you declare BugTable?
its ok, i fixed the problem. BugTable was spelled wrongly for the id of my datagrid.cheers for the help guys

0 comments:

Post a Comment