0

ストアド プロシージャを作成し、ID作成したばかりのもの (ID) を取得したい

これは私がしたことです:

ALTER PROCEDURE [dbo].[SP_Insert_Hai_Pi]
@id INT OUT,
@email VARCHAR(350) = NULL,
@datetimeNow datetime,
@score INT  = 0
AS 

INSERT INTO TBL_HAI_PI (USER_EMAIL,DATETIME_GAME,CORRECT_ANSWERS) VALUES (@email, CURRENT_TIMESTAMP,@score) 

SET @id = SCOPE_IDENTITY();
return @id

その後 :

SqlCommand command = new SqlCommand("SP_Insert_Hai_Pi", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@email", SqlDbType.VarChar).Value = email;

conn.Open();
int tempId = command.ExecuteNonQuery();
conn.Close();
return tempId;

Ttは私に言います:

プロシージャまたは関数 'SP_Insert_Hai_Pi' には、指定されていないパラメーター '@id' が必要です。

どうしたの ?

4

1 に答える 1

0

出力であっても、定義する必要があります。

 ..... 
 command.CommandType = CommandType.StoredProcedure;
 SqlParameter outputIdParam = new SqlParameter("@ID", SqlDbType.Int)
   { 
      Direction = ParameterDirection.Output 
   };

   command.Parameters.Add(outputIdParam);
   command.Parameters.Add("@email", SqlDbType.VarChar).Value = email;
 .....
于 2012-12-05T14:12:27.187 に答える