0

Here is the exception:

"Input string was not in a correct format."

Here is the line of code:

.Add(Integer.Parse(LoanData.Item("IsApplicantRaceAmericanIndian")).ToString)
6
  • 2
    We need to see what LoanData.Item() returns before we can help. it's obviously returning a value that Integer.Parse() can't parse. Commented Jul 28, 2010 at 19:24
  • Why are you turning the Item into a String, then into an Integer? What is it originally? Commented Jul 28, 2010 at 19:24
  • What type is returned from LoanData.Item()? Is it a boolean? A string? Commented Jul 28, 2010 at 19:24
  • It is throwing because the LoanData.Item() returns something that cannot be parsed to an integer. It's kinda obvious. Commented Jul 28, 2010 at 19:25
  • What are the contents of LoanData? What is the value of LoanData.Item("IsApplicantRaceAmericanIndian") ? Are you guaranteed that it will be an Integer? Commented Jul 28, 2010 at 19:26

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.