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

Discussion in 'ASP .Net' started by =?Utf-8?B?YmFzdWxhc3o=?=, Jun 16, 2007.

  1. 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
     
    =?Utf-8?B?YmFzdWxhc3o=?=, Jun 16, 2007
    #1
    1. Advertising

  2. 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

    b> Hi;
    b>
    b> I want to store a datatable (or an arraylist) as a session variable
    b> but when I try;
    b>
    b> Session["_al_RecNo"] = al_RecNo;
    b>
    b> I get an error that;
    b>
    b> "Cannot implicitly convert type 'System.Collections.ArrayList' to
    b> 'string'"
    b>
    b> But I now that we can store objects in session. I have done this
    b> before on VS.NET 2003. What is wrong with that? Is there an option
    b> that we can activate? How can I store an arraylist or a datatable as
    b> a session variable?
    b>
    b> Thanks a lot
    b>
     
    Michael Nemtsev, Jun 16, 2007
    #2
    1. Advertising

  3. 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
    >
    > b> Hi;
    > b>
    > b> I want to store a datatable (or an arraylist) as a session variable
    > b> but when I try;
    > b>
    > b> Session["_al_RecNo"] = al_RecNo;
    > b>
    > b> I get an error that;
    > b>
    > b> "Cannot implicitly convert type 'System.Collections.ArrayList' to
    > b> 'string'"
    > b>
    > b> But I now that we can store objects in session. I have done this
    > b> before on VS.NET 2003. What is wrong with that? Is there an option
    > b> that we can activate? How can I store an arraylist or a datatable as
    > b> a session variable?
    > b>
    > b> Thanks a lot
    > b>
    >
    >
    >
     
    =?Utf-8?B?YmFzdWxhc3o=?=, Jun 16, 2007
    #3
  4. 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

    b> Hi Michael;
    b>
    b> There is noting interesting in the code, just creating arraylists and
    b> defining values like below
    b>
    b> ArrayList al_RecNo = new ArrayList();
    b> ArrayList al_Mess = new ArrayList();
    b> ArrayList al_Type = new ArrayList();
    b> Session["_al_RecNo"] = (object)al_RecNo;
    b> Session["_al_Mess"] = (object)al_Mess;
    b> Session["_al_Type"] = (object)al_Type;
    b> In this case does session state make any sense? For example on my
    b> project there is no definition in web.config file about SessionState.
    b> But on web server the SessionState is configured as InProc and
    b> session variables is stored on web server's local sql database. What
    b> should I do in this case? Should I configure my project to store
    b> variables on local sql server? Is it not possible to store arraylist
    b> or datatable object on session without storing variables on sql
    b> server?
    b>
    b> Thanks...
    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
    >>
    >> b> Hi;
    >> b>
    >> b> I want to store a datatable (or an arraylist) as a session
    >> variable
    >> b> but when I try;
    >> b>
    >> b> Session["_al_RecNo"] = al_RecNo;
    >> b>
    >> b> I get an error that;
    >> b>
    >> b> "Cannot implicitly convert type 'System.Collections.ArrayList' to
    >> b> 'string'"
    >> b>
    >> b> But I now that we can store objects in session. I have done this
    >> b> before on VS.NET 2003. What is wrong with that? Is there an option
    >> b> that we can activate? How can I store an arraylist or a datatable
    >> as
    >> b> a session variable?
    >> b>
    >> b> Thanks a lot
    >> b
     
    Michael Nemtsev, Jun 17, 2007
    #4
  5. 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
     
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=, Jun 17, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,794
    Natty Gur
    Aug 19, 2003
  2. angus
    Replies:
    3
    Views:
    3,350
    Scott Allen
    Jul 8, 2004
  3. Jason
    Replies:
    6
    Views:
    7,510
    Ksenia
    Nov 1, 2005
  4. Kaidi
    Replies:
    4
    Views:
    2,487
    Kaidi
    Jan 3, 2004
  5. xz
    Replies:
    16
    Views:
    2,441
Loading...

Share This Page