943,962 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 8685
  • ASP.NET RSS
Oct 6th, 2004
0

session variable:again

Expand Post »
I really need your help on it.My application is supposed to capture every single user input and store in session variable session("MyCat") in the form of datatable. When page is first loaded, datatable will be initiated and session created. And all subsequent user input will be added in session("MyCat") by adding new rows. My code is as below:
Sub Page_Load(Sender as Object, e as EventArgs)
if NOT IsPostBack then
Dim dTable as DataTable
dTable = New DataTable("mySearch")
dTable.Columns.Add("catagory", System.Type.getType("System.String"))
dTable.Columns.Add("keyword", System.Type.getType("System.String"))
dTable.Columns.Add("ID", System.Type.getType("System.Int32"))
dTable.Columns("ID").AutoIncrement=True
session("myCat")= dTable
end if
end sub


Sub Submit(Sender As Object, e As EventArgs)
dTable=session("myCat")
dim dr as DataRow=dTable.NewRow()
dr(0)=Listbox1.SelectedItem.value
dr(1)=tbtext.Text
dTable.Rows.Add(dr)
session("myCat")= dTable

Anyway, system captures error when
dim dr as DataRow=dTable.NewRow()
is executed.Error message is ystem.NullReferenceException: Object reference not set to an instance of an object
Can any more offer me help on it and let me know if there is any better solution for it...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
EddyJiang is offline Offline
2 posts
since Oct 2004
Apr 14th, 2005
0

Re: session variable:again

Ok, this is the problem
You can't do this per say.

dTable=session("myCat")

but what you shoul do is this:

dTable=CStr(session("myCat"))

You need to convert it to a string. dTable is not set to anything recognizable (as the error message states).

Hope this helps!

*Note* Please use the CODE brackets when displaying several lines of code.
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: looking for downloading asp.net/sqql2000 erp software
Next Thread in ASP.NET Forum Timeline: Getting data from ASP page A to ASP page B using javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC