>>Hi Gerard
>>Because I think you are dealing with an object even though you might have an int in the underlying field. using (int) is an implicit cast and does not work with objects.
>>Tim
>
>That's not really the case. An implicit cast happens automatically - the compiler does the cast for you based on it's internal casting rules.
>
>This is an implicit cast:
>
>
>int myNum = 5;
>decimal newNum = myNum;
>
>
>Convert.ToInt32() can accept objects, strings, bytes, decimals, chars, etc. and it will still successfully convert it.
>
>An explicit cast, like:
>
>
>object myNum = 7;
>int result = (int)myNum;
>
>
>Only works when the underlying cast is valid (and is only evaluated at runtime). The compiler assumes you know what you're doing. So, the most likely reason Convert.ToInt32() is working here is the underlying type in the row isn't actually an Int, but some other number type (or even string).
Yes, I see I didn't really type that right; should have said explicit rather than implicit. I saw from a later post of his the num field he had wasn't really an int as you mentioned which I suspected.
Thanks for setting me straight Paul.
Tim
Timothy Bryan