473,441 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

storing array in session variable

Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?

Nov 17 '05 #1
4 32276
hi,

My advise is that you should read an introductory book to c# , this is
based on both your questions.

This will solve your problem:
txtmyarrat.Text = ((string[])Session["myarray"])[0];

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"mechweb" <me*****@yahoo.com> wrote in message
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Nov 17 '05 #2
Hi,

you've got to cast it back to an array type.

txtmyarray.Text = (string)((Array)Session["myarray"])[0]
or
txtmyarray.Text = ((string[])Session["myarray"])[0]

Christof

"mechweb" <me*****@yahoo.com> schrieb im Newsbeitrag
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Nov 17 '05 #3
In message <uo*************@TK2MSFTNGP09.phx.gbl>, mechweb
<me*****@yahoo.com> writes
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?


Session["myarray"] is returning type object. Cast it to string[] before
trying to access it as such.

--
Steve Walker
Nov 17 '05 #4
Thanks for the quick response, that did it!

"Christof Nordiek" <cn@nospam.de> wrote in message
news:u1**************@TK2MSFTNGP14.phx.gbl...
Hi,

you've got to cast it back to an array type.

txtmyarray.Text = (string)((Array)Session["myarray"])[0]
or
txtmyarray.Text = ((string[])Session["myarray"])[0]

Christof

"mechweb" <me*****@yahoo.com> schrieb im Newsbeitrag
news:uo*************@TK2MSFTNGP09.phx.gbl...
Hi all, I can successfully store an array in a session variable like so:
string[] arr1 = new string[10];

Session["myarray"] = arr1;

But, when I try to display the elements (using the code below) on another
page I get this error:

txtmyarray.Text = Session["myarray"][0];

Cannot apply indexing with [] to an expression of type 'object'

The weird thing is that the code works fine in the immediate window while
debugging. Any thoughts?



Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: | last post by:
Hi, I want to do things this way: I have a bunch of stuff that I want to keep track of while a user is connected to the site. Maybe 50 little peices of information. So I know I can make 50...
4
by: GJones | last post by:
Is there away to capture a session variable value from IIS and use it in a SQL 2000 trigger with out passing it as a part of a string query. I just want to capture it somehow systemically. ...
3
by: Neil Jarman | last post by:
Hi, I need to create an array with a session variable. According to thebook I'm using, the following should work, but if fails: for each key in request.QueryString if left(key,6) = "cboRun"...
0
by: Sandra | last post by:
I am using a VB6 COM object with an asp.net project. I am storing the COM object in a session variable but am having a problem accessing the COM object from the session variable. I am getting...
3
by: Tillman Erb | last post by:
Let's assume a database with a parent table and a child table in a one-to-many relationship, respectively. I have a DataList control on page P that displays values from the parent table. Each row...
4
by: MrBiggles | last post by:
Here's the sitch: I read in a csv file with 60000 lines (20 fields per record), and store the data to a local array. The file is read in and stored just fine and pretty quick. Now, if I try to...
5
by: TRB_NV | last post by:
I'm losing information from my Session when I change pages or start the same page over again. I simplified the code so the example is really clear. The sample code that follows is supposed to...
1
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
3
by: RSH | last post by:
Hi, I have a situation where I have created an object that contains fields,properties and functions. After creating the object I attempted to assign it to a session variable so i could retrieve...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.