2
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;

}

4

1 回答 1

1

尝试将参数方向设置为输出。

noteid.Direction = ParameterDirection.Output;
于 2013-11-05T16:14:59.473 回答