错误:输入字符串的格式不正确。 [英] Error :Input string was not in a correct format.

查看:250
本文介绍了错误:输入字符串的格式不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hye,我有以下代码行,其中Parent_ID数据类型是int?

从数据库中它可以返回整数或null,当返回null时,它是由一个问题得到的?... .................................帮帮我PLZ .............. .........





Parent_ID = int.Parse(dr [Parent_ID]。ToString()) ;

Hye, i have following code of line, where the Parent_ID datatype is int?
from database it can return integer or null,when returns null ,it is gotten by a problem?....................................help me plz.......................


Parent_ID= int.Parse(dr["Parent_ID"].ToString());

推荐答案

dr [Parent_ID]。ToString()并不总是有效的 int ie它也可以返回 null 。然后你应该尝试使用 int.TryParse 函数进行强制转换。有关详细信息,请查看此信息: http://www.dotnetperls.com/int-tryparse [ ^ ]
dr["Parent_ID"].ToString() is not always a valid int i.e. it could return null too. then parhaps you should try to use int.TryParse function to do the cast. Check this for more details: http://www.dotnetperls.com/int-tryparse[^]


这篇关于错误:输入字符串的格式不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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