DataTable in a Session variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jpabich

    DataTable in a Session variable

    How do I define, store and retrieve a dataTable from a Session variable?

  • Cor Ligthert [MVP]

    #2
    Re: DataTable in a Session variable

    jpabick,

    Add it first to a dataset, than it is very simple (typed here watch errors)


    DataSet ds = new DataSet();
    ds.Tables.Add(m yTable)
    Session.Item("d s") = ds;

    I hope this helps,

    Cor
    "jpabich" <jpabich@eisinc orporated.comsc hreef in bericht
    news:1157992861 .468945.264330@ i42g2000cwa.goo glegroups.com.. .
    How do I define, store and retrieve a dataTable from a Session variable?
    >

    Comment

    • jpabich

      #3
      Re: DataTable in a Session variable

      I don't think this helps. I need the session variable to be able to be
      accessed from another screen. I have it defined as;

      /// <summary>
      /// Session variable to hold the execption table
      /// </summary>
      public static DataTable SESSION_EXCEPTI ON_TABLE = null;

      Add Table to it as;

      HttpContext.Cur rent.Session[SESSION_EXCEPTI ON_TABLE] =
      ViewState["dtbExcepti on"];


      Retrieve it as:
      dtbWrite =
      Convert.ToStrin g(HttpContext.C urrent.Session[RecordCount.SES SION_EXCEPTION_ TABLE]);

      I get complie errors on all of this.

      Cor Ligthert [MVP] wrote:
      jpabick,
      >
      Add it first to a dataset, than it is very simple (typed here watch errors)
      >
      >
      DataSet ds = new DataSet();
      ds.Tables.Add(m yTable)
      Session.Item("d s") = ds;
      >
      I hope this helps,
      >
      Cor
      "jpabich" <jpabich@eisinc orporated.comsc hreef in bericht
      news:1157992861 .468945.264330@ i42g2000cwa.goo glegroups.com.. .
      How do I define, store and retrieve a dataTable from a Session variable?

      Comment

      • Marina Levit [MVP]

        #4
        Re: DataTable in a Session variable

        C# is strongly typed, so you have to cast anything you get out of session to
        its appropriate data type.

        Also, if what you are putting into session is a DataTable, why are you
        converting it to a string when you take it out?

        "jpabich" <jpabich@eisinc orporated.comwr ote in message
        news:1157994430 .706222.78360@d 34g2000cwd.goog legroups.com...
        >I don't think this helps. I need the session variable to be able to be
        accessed from another screen. I have it defined as;
        >
        /// <summary>
        /// Session variable to hold the execption table
        /// </summary>
        public static DataTable SESSION_EXCEPTI ON_TABLE = null;
        >
        Add Table to it as;
        >
        HttpContext.Cur rent.Session[SESSION_EXCEPTI ON_TABLE] =
        ViewState["dtbExcepti on"];
        >
        >
        Retrieve it as:
        dtbWrite =
        Convert.ToStrin g(HttpContext.C urrent.Session[RecordCount.SES SION_EXCEPTION_ TABLE]);
        >
        I get complie errors on all of this.
        >
        Cor Ligthert [MVP] wrote:
        >jpabick,
        >>
        >Add it first to a dataset, than it is very simple (typed here watch
        >errors)
        >>
        >>
        >DataSet ds = new DataSet();
        >ds.Tables.Add( myTable)
        >Session.Item(" ds") = ds;
        >>
        >I hope this helps,
        >>
        >Cor
        >"jpabich" <jpabich@eisinc orporated.comsc hreef in bericht
        >news:115799286 1.468945.264330 @i42g2000cwa.go oglegroups.com. ..
        How do I define, store and retrieve a dataTable from a Session
        variable?
        >
        >

        Comment

        • Ignacio Machin \( .NET/ C# MVP \)

          #5
          Re: DataTable in a Session variable

          Hi ,



          if you declare your dataset static it will not be scoped in your session but
          in your Application, all the sessions will share teh same dataset !!!
          Add Table to it as;
          >
          HttpContext.Cur rent.Session[SESSION_EXCEPTI ON_TABLE] =
          ViewState["dtbExcepti on"];
          You have errors there, Session expect either a string or a integer to
          retrive from the session collection, a DataTable will not compile, change it
          to:
          Session["Exception_Tabl e"] = ....;

          >
          Retrieve it as:
          dtbWrite =
          Convert.ToStrin g(HttpContext.C urrent.Session[RecordCount.SES SION_EXCEPTION_ TABLE]);
          Idem.

          Again, you are declaring the datatable as static, this is an error !
          OR you dont want it in session


          What is what you are trying to do in the first place?


          --
          --
          Ignacio Machin,
          ignacio.machin AT dot.state.fl.us
          Florida Department Of Transportation


          Comment

          Working...