| | |
session variable:again
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
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 beginner bottomasp.net browser businesslogiclayer c# cac checkbox class commonfunctions compatible content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iframe iis javascript listbox menu microsoft mouse mssql multistepregistration nameisnotdeclared news opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers





