错误:无法转换类型'System.Int32'的对象类型'System.String' [英] Error: Unable to cast object of type 'System.Int32' to type 'System.String'

查看:881
本文介绍了错误:无法转换类型'System.Int32'的对象类型'System.String'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有完美的完成编码注册页面,登录现在UpdateCustomer网页有错误 - 背景信息:我使用的是Microsoft Access作为数据源

  LabelState.Text =(字符串)会议[sState]; 
LabelPostalCode.Text =(字符串)会议[sPostalCode];
LabelContactNumber.Text =(字符串)会议[sContactNumber];
LabelEmail.Text =(字符串)会议[sEmail];
LabelPassword.Text =(字符串)会议[spassword开头];这里



一切都很好,除了 LabelContactNumber.Text =(字符串)会议[ sContactNumber]



我相信这是因为只有ContactNumber在访问权限设置为INT其余因此文本有,当我使用没有错误(串)。


解决方案

  LabelContactNumber.Text =(会话[sContactNumber]!= NULL)
'会话[sContactNumber]的ToString()
://的String.Empty或任何默认值你想;


I have finish perfectly coding Register Page, Login and now the UpdateCustomer page has errors - Background info : I'm using Microsoft Access as data source

    LabelState.Text = (string)Session["sState"];
    LabelPostalCode.Text = (string)Session["sPostalCode"];
    LabelContactNumber.Text = (string)Session["sContactNumber"];
    LabelEmail.Text = (string)Session["sEmail"];
    LabelPassword.Text = (string)Session["sPassword"];

Everything here is fine except LabelContactNumber.Text = (string)Session["sContactNumber"].

I believe it is because only ContactNumber in Access is set as Int the rest is Text therefore there's no error when I use (string).

解决方案

LabelContactNumber.Text = (Session["sContactNumber"] != null)
                              ? Session["sContactNumber"].ToString()
                              : string.Empty //or whatever default value your want;

这篇关于错误:无法转换类型'System.Int32'的对象类型'System.String'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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