Click here to Skip to main content
15,923,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i want to store data set in session is it possible, if possible how can i assign and how to retrieve data to display in gridview.

how can i do that ?
Posted
Updated 19-Sep-11 18:16pm
v2

 
Share this answer
 
yes you can store dataset in session

while assigning
session["mydataset"]=ds;



while retrieving

dataset ds=(dataset)session["mydataset"];


gridview.datasource=ds.tables[0];
gridview.databind();
 
Share this answer
 
v2
Session variable can store large amount of data, including class, dataset.

here is example how we can store dataset in session

C#
Session["objDS"] = objDataset


retrive back to dataset from session variable

C#
dataset objDS =(dataset) session["objDS"]; //it needs casting to dataset
 
Share this answer
 
u can save dataset to Session variable as follows:
Session["Table"] = ds.Tables[0];
to retreive it u need not to call again DB just retrieve it from Session as

DataSet ds=new DataSet();
ds = (DataSet)Session["Table"];
 
Share this answer
 
C#
// TO Initialize
Session["MyDataSet"] = MyDataSet;
// TO Retrieve
MyRecDataSet = (DataSet) Session["MyDataSet"];
 
Share this answer
 
VB
Dim ds as New DataSet
Session("DataSet")=ds
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900