Return Value from a Stored Procedure

后端 未结 2 860
不知归路
不知归路 2021-01-23 14:34

I am trying to get data returned from my stored procedure. This is what I have tried and absolutely nothing is coming back.

Stored Proc:

Declare @Submit_         


        
2条回答
  •  不思量自难忘°
    2021-01-23 15:03

    You're not adding the return parameter to the command:

    SqlParameter pSub = new SqlParameter("@Sub_ID", SqlDbType.Int);
    pSub.Direction = ParameterDirection.ReturnValue;
    
    cmd.Parameters.Add(pSub);    // <-------------  add to command
    
    conn.Open();
    cmd.ExecuteNonQuery();
    
    subid = Convert.ToInt32(cmd.Parameters["pSub"].Value);
    

提交回复
热议问题