ALTER PROCEDURE dbo.spReturnLastRowNoteID
(@noteid int OUTPUT)
AS
SET NOCOUNT ON
SELECT @noteid = NoteID
FROM NoteTable
WHERE NoteID = IDENT_CURRENT('NoteTable')
RETURN @noteid`
我认为我的 sp 和代码没有问题,但我不确定为什么会出现错误:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string sqlSearchCommand = "spReturnLastRowNoteID";
SqlCommand command = new SqlCommand(sqlSearchCommand, connection);
command.CommandType = CommandType.StoredProcedure;
SqlParameter noteid = command.Parameters.Add("@noteid", SqlDbType.Int);
noteid.Direction = ParameterDirection.ReturnValue;
command.ExecuteNonQuery();
lastnoteid = (int)command.Parameters["@noteid"].Value;
}