Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing and retrieving datatable from session

Tags:

c#

.net

How to store a datatable in session and to retrieve the values from the session in c#.net?

like image 451
subash Avatar asked Feb 18 '10 11:02

subash


People also ask

Can we store data table in session?

You can do it like that but storing a DataSet object in Session is not very efficient. If you have a web app with lots of users it will clog your server memory really fast. If you really must do it like that I suggest removing it from the session as soon as you don't need the DataSet. Save this answer.


2 Answers

Add a datatable into session:

DataTable Tissues = new DataTable();

Tissues = dal.returnTissues("TestID", "TestValue");// returnTissues("","") sample     function for adding values


Session.Add("Tissues", Tissues);

Retrive that datatable from session:

DataTable Tissues = Session["Tissues"] as DataTable

or

DataTable Tissues = (DataTable)Session["Tissues"];
like image 58
amexn Avatar answered Oct 16 '22 08:10

amexn


To store DataTable in Session:

DataTable dtTest = new DataTable();
Session["dtTest"] = dtTest; 

To retrieve DataTable from Session:

DataTable dt = (DataTable) Session["dtTest"];
like image 44
Prashant Wagh Avatar answered Oct 16 '22 10:10

Prashant Wagh