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 に答える