SCOPE_IDENTITY()取得返回在当前会话中的任何表内所生成的最后一个标识值
比如新增一条记录,获得插入记录的ID号
var pramTotalRowCount = new SqlParameter("@PKID", SqlDbType.Int) { Direction = ParameterDirection.Output }; var parameters = new[] { new SqlParameter("@ID", srcs.ShopID), new SqlParameter("@Name", srcs.UserName), pramTotalRowCount }; string sql = @"INSERT INTO Tuhu_shop..ShopReceiveCheckSecond ( ID , Name ) VALUES ( @ID , @Name); SET @PKID = SCOPE_IDENTITY();"; SqlHelper.ExecuteNonQuery(connection, CommandType.Text, sql, parameters); long pkid = 0; long.TryParse(pramTotalRowCount.Value.ToString(), out pkid); return pkid;