User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,774 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,359 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 5676 | Replies: 1
Reply
Join Date: Oct 2004
Posts: 2
Reputation: EddyJiang is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
EddyJiang EddyJiang is offline Offline
Newbie Poster

session variable:again

  #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...
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 26
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: session variable:again

  #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, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 4:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC