开发者

Exception when Parsing String VB.NET

Here is the exception:

"Input string was not in a correct format."

Here is the line of code:

.Add(Integer.Parse(LoanData.Item("开发者_JS百科IsApplicantRaceAmericanIndian")).ToString)


The text you're trying to parse must not represent a valid integer. For example it might be "ABC" or it might be blank.

Use Integer.TryParse instead of Integer.Parse for a more resilient parsing strategy:

Dim text As String = LoanData.Item("IsApplicantRaceAmericanIndian")).ToString()

Dim value As Integer
If Integer.TryParse(text, value)
    .Add(value)
Else
    ' The text could not be parsed. '
    ' Notify the user, log it, do whatever you like. '
End If


As a tip, Integer.Parse won't handle empty or null strings. Try using Integer.TryParse if you are using .NET 2.0 or newer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜