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());
Use SCOPE_IDENTITY… which is correct and decimal(38,0) anyway…
However, you should note that @@IDENTITY is also decimal(38,0)
This is because it must encompass any datatype that can be autonumbered such as decimal and bigint
Edit:
Apparently it’s caused by unboxing. YMMV.