开发者

Exception when Parsing String VB.NET

开发者 https://www.devze.com 2023-01-09 12:30 出处:网络
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)

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

精彩评论

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

关注公众号