Return Value from a Stored Procedure

后端 未结 2 857
不知归路
不知归路 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);
    
    0 讨论(0)
  • 2021-01-23 15:13

    First add parameter to cmd and use .Value to its value

     cmd.Parameters.Add(pSub);    // add parameters to command
     cmd.ExecuteNonQuery();
     subid = Convert.ToInt32(pSub.Value); // Use .Value
    
    0 讨论(0)
提交回复
热议问题