错误:输入字符串的格式不正确。 [英] Error :Input string was not in a correct format.
本文介绍了错误:输入字符串的格式不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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 validint
i.e. it could returnnull
too. then parhaps you should try to useint.TryParse
function to do the cast. Check this for more details: http://www.dotnetperls.com/int-tryparse[^]
这篇关于错误:输入字符串的格式不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文