DataTable in a Session variable

  • Thread starter Thread starter jpabich
  • Start date Start date
J

jpabich

How do I define, store and retrieve a dataTable from 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(myTable)
Session.Item("ds") = ds;

I hope this helps,

Cor
 
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_EXCEPTION_TABLE = null;

Add Table to it as;

HttpContext.Current.Session[SESSION_EXCEPTION_TABLE] =
ViewState["dtbException"];


Retrieve it as:
dtbWrite =
Convert.ToString(HttpContext.Current.Session[RecordCount.SESSION_EXCEPTION_TABLE]);

I get complie errors on all of this.
 
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 said:
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_EXCEPTION_TABLE = null;

Add Table to it as;

HttpContext.Current.Session[SESSION_EXCEPTION_TABLE] =
ViewState["dtbException"];


Retrieve it as:
dtbWrite =
Convert.ToString(HttpContext.Current.Session[RecordCount.SESSION_EXCEPTION_TABLE]);

I get complie errors on all of this.
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
 
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.Current.Session[SESSION_EXCEPTION_TABLE] =
ViewState["dtbException"];

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_Table"] = ....;

Retrieve it as:
dtbWrite =
Convert.ToString(HttpContext.Current.Session[RecordCount.SESSION_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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top