views:

26

answers:

2

Hello, just wondering if how can we retrieve a data from stored procedure, who's return value is not in a row. I've run the stored procedure and it doesn't return any rows but return some data >.< just like this photo. could anyone know how to retrieve return value @rtncode in .NET?

alt text

Thanks!

+1  A: 

Typically such Stored Procedures are invoked by way of the ExecuteNonQuery method of an SqlCommand (from System.Data.SqlClient).

Both output parameters or the return value are populated by ExecuteNonQuery.

mjv
+2  A: 

Here's some sample code on using an OUTPUT parameter and ADO.NET

using(SqlConnection conn = new SqlConnection("YOUR_CONNECTION_STRING"))
{
    conn.Open();
    using (SqlCommand command = conn.CreateCommand())
    {
        command.CommandType = CommandType.StoredProcedure;

        SqlParameter parameter = command.Parameters.Add("@yourParameter", SqlDbType.VarChar, 50);
        parameter.Direction = ParameterDirection.Output;

        command.CommandText = "YOUR_STORED_PROCEDURE";
        command.ExecuteNonQuery();
        return parameter.Value;    
    }
}
Kane
Thanks you sir! :)
Sherwin Valdez