You can't cast anything to an integer if it is not an integer. But you can
convert:
int contractId = System.Convert.ToInt32(cmd.ExecuteScalar());
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jonathan Wood" <(E-Mail Removed)> wrote in message
news:%23fYD$0h$(E-Mail Removed)...
> Er... When it's a Decimal.
>
> I'm executing a query that includes the following: "INSERT INTO [...];
> SELECT SCOPE_IDENTITY()"
>
> I then attempt to retrieve the scope identity with code that looks like
> this:
>
> int contractId = (int)cmd.ExecuteScalar();
>
> I get an "Invalid cast" error. Examing the value returned by
> ExecuteScalar(), I see it is 19 and of type Decimal.
>
> Can anyone explain to me why a Decimal with a value of 19 cannot be cast
> to an integer?
>
> Thanks.
>
> Jonathan
>