将新值添加到会话中,而不会丢失c#.net中的旧值 [英] Add new value to session without lost old values in c#.net
本文介绍了将新值添加到会话中,而不会丢失c#.net中的旧值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..朋友,我有一个Web应用程序,其中将一些值存储在
中
Session ["dbValues"],但我的问题是,我想在此会话中添加一些新数据而又不会丢失旧数据.
例如,我的Session ["dbValues"]的值为1,然后我要添加新的值2
谢谢与问候
Parveen Rathi
Hi.. Friends, I have a web application in which I am storing some value in
Session["dbValues"] but my problem is, I want to add some new data in this session without lost the old data.
For example I my Session["dbValues"] has value 1 then I want to add new value 2
Thanks & Regard
Parveen Rathi
推荐答案
假设您正在使用DataTable来保存值,请参见以下解决方案:
Assuming you are using DataTable to hold the values, pleasee see the following solution :
DataTable dt = Session["dbValues"] as DataTable;
DataRow dr = dt.NewRow();
// add data to the new row
// i.e. dr["name"]="something";
// add this row to DT now
dt.Rows.Add(dr);
// assign this modified Datatable back to Session
Session["dbValues"] = dt;
同样,您可以键入强制转换您在Session中持有的任何对象并对其进行操作,然后将其重新分配给同一会话变量.
Similarly, You can type cast any object that you are holding in Session and manipulate the object and re-assign it to same session variable.
它取决于要存储在Session
上的数据,如果它是字符串,则可以使用Append
还是可以使用Array
最好的问候
米特瓦里(M.Mitwalli)
Hi ,
It depend on the data you want to store it onSession
if it String you can useAppend
or you can useArray
Best Regards
M.Mitwalli
这篇关于将新值添加到会话中,而不会丢失c#.net中的旧值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文