如何在会话变量中存储数据集 [英] How to store dataset in session variable

查看:51
本文介绍了如何在会话变量中存储数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to store datatable or dataset in session..and what are the advantages and limitations on that 





我尝试了什么:



我想将15个记录从一个页面传递到另一个页面,这是使用数据表会话的正确方法??



What I have tried:

I want to pass 15 records from one page to another,it's a right way to use session with datatable??

推荐答案

试试这个: -



Try this:-

Session["xyz"]=ds;





或者您可以参考以下链接:



在会话中存储数据集 [ ^ ]


使用会话带来一些问题:

1.会话结束后会话中存储的数据(用户去喝咖啡)

2.会话数据使用的内存主机,如此大/多会话可能会导致性能问题如果硬件没有缩放...



这15条记录的来源绝对不清楚,但最好只在页面间传递单个参数而不是垃圾数据......

例如,当您打开作者的书籍列表时,作者从列表中选择,您只将作者ID传递到下一页,并且由该页面加载相关书籍列表......
To use session brings a few problems:
1. Data stored on session gone when session is out (user went to drink a coffee)
2. Session data uses the memory of the host computer, so big/numerous sessions can cause performance problems if hardware is not scaling with...

It is absolutely unclear from where those 15 records came, but it was better to pass only single parameters between pages and not junk of data...
For instance when you open a list of books of an author, where the author picked from a list, you only pass the author id to the next page and it is the responsibility of that page to load the list of relevant books...


在会话中存储记录列表不是一个好习惯。



在您获取数据的第一页?

通过在会话的帮助下在第二页中传递单个参数,你可以检索第二页中的记录列表。



让我们说:

您在第一页中有一个ID的记录列表。您可以在会话的帮助下将该ID作为参数传递给第二页。



Ex:



第一页:



会话[Keyname] =YourValue;





第二页:



您可以检索该会话密钥中的记录列表。



---------------------

根据问题,如果你想将ds设置为session,那么这里是代码。



设置:在第一页

DataSet ds = new DataSet();



Session [KeyName] = ds;



进入第2页:



DataSet ds =(DataSet)Session [KeyName];



------------
It is not the good practice to store a list of records in session.

In the first page from where you get the data?
Same way you can retrieve the list of records in 2nd page by passing the single parameter in 2nd page by the help of session.

let say:
You have a list of records of one ID in first page. You can pass that ID as parameter in 2nd page by the help of session.

Ex:

Firstpage:

Session["Keyname"]="YourValue";


2nd Page:

You can retrieve the list of records in of that session key.

---------------------
As per the question if you want to set the ds to session then here is the code.

Set: In first page
DataSet ds=new DataSet();

Session["KeyName"]= ds;

Get in 2nd page:

DataSet ds= (DataSet) Session["KeyName"];

------------


这篇关于如何在会话变量中存储数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆