467,922 Members | 1,289 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,922 developers. It's quick & easy.

Storing a datatable (or arraylist )on ASP.NET Session

Hi;

I want to store a datatable (or an arraylist) as a session variable but when
I try;

Session["_al_RecNo"] = al_RecNo;

I get an error that;

"Cannot implicitly convert type 'System.Collections.ArrayList' to 'string'"

But I now that we can store objects in session. I have done this before on
VS.NET 2003. What is wrong with that? Is there an option that we can
activate? How can I store an arraylist or a datatable as a session variable?

Thanks a lot
Jun 16 '07 #1
  • viewed: 12336
Share:
4 Replies
Hello basulasz,

could you demonstrate your code?

Seems that you are using the outproc session state, where your object in
session must be serializable

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

bHi;
b>
bI want to store a datatable (or an arraylist) as a session variable
bbut when I try;
b>
bSession["_al_RecNo"] = al_RecNo;
b>
bI get an error that;
b>
b"Cannot implicitly convert type 'System.Collections.ArrayList' to
b'string'"
b>
bBut I now that we can store objects in session. I have done this
bbefore on VS.NET 2003. What is wrong with that? Is there an option
bthat we can activate? How can I store an arraylist or a datatable as
ba session variable?
b>
bThanks a lot
b>
Jun 16 '07 #2
Hi Michael;

There is noting interesting in the code, just creating arraylists and
defining values like below

ArrayList al_RecNo = new ArrayList();
ArrayList al_Mess = new ArrayList();
ArrayList al_Type = new ArrayList();

Session["_al_RecNo"] = (object)al_RecNo;
Session["_al_Mess"] = (object)al_Mess;
Session["_al_Type"] = (object)al_Type;

In this case does session state make any sense? For example on my project
there is no definition in web.config file about SessionState. But on web
server the SessionState is configured as InProc and session variables is
stored on web server's local sql database. What should I do in this case?
Should I configure my project to store variables on local sql server? Is it
not possible to store arraylist or datatable object on session without
storing variables on sql server?

Thanks...

"Michael Nemtsev" wrote:
Hello basulasz,

could you demonstrate your code?

Seems that you are using the outproc session state, where your object in
session must be serializable

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

bHi;
b>
bI want to store a datatable (or an arraylist) as a session variable
bbut when I try;
b>
bSession["_al_RecNo"] = al_RecNo;
b>
bI get an error that;
b>
b"Cannot implicitly convert type 'System.Collections.ArrayList' to
b'string'"
b>
bBut I now that we can store objects in session. I have done this
bbefore on VS.NET 2003. What is wrong with that? Is there an option
bthat we can activate? How can I store an arraylist or a datatable as
ba session variable?
b>
bThanks a lot
b>
Jun 16 '07 #3
Hello basulasz,

That code works fine. Have you tried to run that in new project.
Perhaps your ArrayList store smth which can't be casted to object. If exactly
that code u shown didn't work (emply arraylists) that I recomment to re-register
asp.net 2.0 calling aspnet_regiis,exe - i

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

bHi Michael;
b>
bThere is noting interesting in the code, just creating arraylists and
bdefining values like below
b>
bArrayList al_RecNo = new ArrayList();
bArrayList al_Mess = new ArrayList();
bArrayList al_Type = new ArrayList();
bSession["_al_RecNo"] = (object)al_RecNo;
bSession["_al_Mess"] = (object)al_Mess;
bSession["_al_Type"] = (object)al_Type;
bIn this case does session state make any sense? For example on my
bproject there is no definition in web.config file about SessionState.
bBut on web server the SessionState is configured as InProc and
bsession variables is stored on web server's local sql database. What
bshould I do in this case? Should I configure my project to store
bvariables on local sql server? Is it not possible to store arraylist
bor datatable object on session without storing variables on sql
bserver?
b>
bThanks...
b>
b"Michael Nemtsev" wrote:
b>
>Hello basulasz,

could you demonstrate your code?

Seems that you are using the outproc session state, where your object
in session must be serializable

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high
and we miss it, but that it is too low and we reach it" (c)
Michelangelo

bHi;
b>
bI want to store a datatable (or an arraylist) as a session
variable
bbut when I try;
b>
bSession["_al_RecNo"] = al_RecNo;
b>
bI get an error that;
b>
b"Cannot implicitly convert type 'System.Collections.ArrayList' to
b'string'"
b>
bBut I now that we can store objects in session. I have done this
bbefore on VS.NET 2003. What is wrong with that? Is there an option
bthat we can activate? How can I store an arraylist or a datatable
as
ba session variable?
b>
bThanks a lot
b>

Jun 17 '07 #4
basulasz wrote:
Hi Michael;

There is noting interesting in the code, just creating arraylists and
defining values like below

ArrayList al_RecNo = new ArrayList();
ArrayList al_Mess = new ArrayList();
ArrayList al_Type = new ArrayList();

Session["_al_RecNo"] = (object)al_RecNo;
Session["_al_Mess"] = (object)al_Mess;
Session["_al_Type"] = (object)al_Type;

In this case does session state make any sense? For example on my project
there is no definition in web.config file about SessionState. But on web
server the SessionState is configured as InProc and session variables is
stored on web server's local sql database.
Which is it? InProc means that the sessions are stored in memory, not in
an SQL Server database.

If the web.config contains settings for an SQL Server database, but the
mode is InProc, the rest of the settings are ignored.
What should I do in this case?
Should I configure my project to store variables on local sql server? Is it
not possible to store arraylist or datatable object on session without
storing variables on sql server?
The opposite. Using InProc you can store most objects in session
variables, but using a database they have to be serializable.

--
Göran Andersson
_____
http://www.guffa.com
Jun 17 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by VMI | last post: by
1 post views Thread by Maziar Aflatoun | last post: by
1 post views Thread by Grey | last post: by
4 posts views Thread by tma | last post: by
2 posts views Thread by Al Wilkerson | last post: by
2 posts views Thread by Curt tabor | last post: by
12 posts views Thread by Alex D. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.