• 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

suityou01

Potty-trained
Joined
Jan 20, 2009
Messages
21,122
Likes received
773
Thanks received
222
Location
Clown World
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. :suicide:

Googling but not really getting anywhere.
 
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: 11:17
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. :suicide:
 

Advertisers

Back
Top