How to get Identity value from SQL server after insert record
问题 I add a record in my database with an identity value. I want to get the identity value after inserting. I don't want to do that by stored procedure. This is my code: SQLString = " INSERT INTO myTable "; SQLString += " (Cal1, Cal2, Cal3, Cal4) "; SQLString += " VALUES(N'{0}',N'{1}',N'{2}',N'{3}') "; SQLString = string.Format(SQLString, Val1, Val2, Val3, Val4); SQLString += " Declare @_IdentityCode INT SET @_IdentityCode = @@IDENTITY RETURN @_IdentityCode"; int result; public int DoCommand2