session variable:again

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 2
Reputation: EddyJiang is an unknown quantity at this point 
Solved Threads: 0
EddyJiang EddyJiang is offline Offline
Newbie Poster

session variable:again

 
0
  #1
Oct 6th, 2004
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...
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: session variable:again

 
0
  #2
Apr 14th, 2005
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.
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC