Get Return Value from Stored procedure in asp.net

前端 未结 6 1167
既然无缘
既然无缘 2020-12-10 11:19

i have a stored procedure

ALTER PROC TESTLOGIN
    @UserName varchar(50),
    @password varchar(50)
As
Begin
    declare @return int;

    set @return  = (S         


        
6条回答
  •  再見小時候
    2020-12-10 12:03

    2 things.

    • The query has to complete on sql server before the return value is sent.

    • The results have to be captured and then finish executing before the return value gets to the object.

    In English, finish the work and then retrieve the value.

    this will not work:

                    cmm.ExecuteReader();
                    int i = (int) cmm.Parameters["@RETURN_VALUE"].Value;
    

    This will work:

                            SqlDataReader reader = cmm.ExecuteReader();
                            reader.Close();
    
                            foreach (SqlParameter prm in cmd.Parameters)
                            {
                               Debug.WriteLine("");
                               Debug.WriteLine("Name " + prm.ParameterName);
                               Debug.WriteLine("Type " + prm.SqlDbType.ToString());
                               Debug.WriteLine("Size " + prm.Size.ToString());
                               Debug.WriteLine("Direction " + prm.Direction.ToString());
                               Debug.WriteLine("Value " + prm.Value);
    
                            }
    

    if you are not sure check the value of the parameter before during and after the results have been processed by the reader.

提交回复
热议问题