象这样的语句
command.CommandText =
“
INSERT
……;SELECT @@IDENTITY;
”
;
int
iRe = (int)command.ExecuteScalar();
在
C#
里面,一直都没发现有什么问题。
可以写在
CLR
程序集里,给
SQL
SERVER 2005
执行,就有问题,报错:
Specified cast is not valid
(数据类型转换出错。)
后来换成
int
iRe = Convert.ToInt32(command.ExecuteScalar());
就可以鸟。真奇怪,原本改成
Int32
iRe = (Int32)command.ExecuteScalar();
都不行。