| | |
session variable:again
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 2
Reputation:
Solved Threads: 0
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...
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 objectCan any more offer me help on it and let me know if there is any better solution for it...
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.
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.
![]() |
Similar Threads
- session variable error (PHP)
- calling session variable (ASP.NET)
- Session Variable clashing (ASP.NET)
- Losing session variable problem...help! (ASP)
- session variable undefined in MX 6.1, works in CF 5 (ColdFusion)
- Session variable (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: looking for downloading asp.net/sqql2000 erp software
- Next Thread: Getting data from ASP page A to ASP page B using javascript
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu dynamically edit fill flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery list listbox menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects opera order panelmasterpagebuttoncontrols radio ratings registration reportemail rotatepage schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





