如何将会话值转换为字符串 [英] how to convert session value to string
本文介绍了如何将会话值转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须将会话值设置为字符串数据类型。
对于Ex:
i have to asign session value to string datatype.
For Ex:
string str=session["name"].ToString();
但是这会给我错误。问题是什么?
but this will give me error.what is problem?
推荐答案
试试这个
Try this
string str=string.empty;
str=convert.tostring(session["name"]);
谢谢
Thanks
会话值得到这样你写的代码。
firstly说什么是错误。
因为它给出了空值。
你也可以使用: -
Session value get like this you was write code.
firstly say what is error.
as it give null value.
YOU CAN ALSO USED :-
string firstName = (string)(Session["First"]);
OR
OR
string str=session["name"].ToString();
为此您需要检查您的会话变量是否存在或已过期,abonden。
所以你需要阅读以下链接:=
http://msdn.microsoft.com/en-us/library/03sekbw5(v = vs.100).aspx [ ^ ]
如果你得到的话错误空对象或未设置对象引用到...
然后
if you are getting error null object or object reference not set to...
then
string str = "";
if (session["name"] != null)
{
str = session["name"].ToString();
}
快乐编码!
:)
Happy Coding!
:)
这篇关于如何将会话值转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文