make select @@IDENTITY; a long?

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-05-21T19:01:45Z Indexed on 2010/05/21 19:10 UTC
Read the original article Hit count: 117

Filed under:
|
|

I am grabbing the last rowid and i am doing this select @@IDENTITY

 pk = (long)cmd.ExecuteScalar();

I get an invalid typecast bc this is int instead of long. Why doesnt this return a long? can i make it return long?

Solution for now is to use

 pk = Convert.ToInt64(cmd.ExecuteScalar());

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about ADO.NET