• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Nice error message

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Nice error message

    Consider the following c# 2005 code

    if (!row["ISOC"].Equals((object)DBNull.Value))
    {
    retval[cnt].isoc = (Int32)row["ISOC"];
    }

    Now my object in the array has an isoc property, of type Int32.

    The value of row["ISOC"] is 177.

    The error I get is

    When casting from a number, the value must be a number less than infinity.

    Now the last time I checked, 177 was less than infinity.

    Googling but not really getting anywhere.
    Knock first as I might be balancing my chakras.

    #2
    Use the Convert.ToInt32 method.

    Move all those comparisons and conversions into helper methods to cut down coding.

    I suspect your row does not contain 177.

    Also, what's with all this:

    if (!row["ISOC"].Equals((object)DBNull.Value))

    rather than

    if (row["ISOC"] != DBNull.Value)


    Are you paid per character typed?
    Last edited by DimPrawn; 24 July 2009, 10:20.

    Comment


      #3
      Originally posted by DimPrawn View Post
      Use the Convert.ToInt32 method.

      Move all those comparisons and conversions into helper methods to cut down coding.

      I suspect your row does not contain 177.
      Definately does contain 177. Bizarre error message.

      By casting the row item to a string, and then using Int32.parse it works. I shall also try your suggestion.

      What's wrong with a good old "data type mismatch" error FFS.
      Knock first as I might be balancing my chakras.

      Comment

      Working...
      X