views:

26

answers:

1

I am trying to get the output of a stored procedure into a function but with my code i am always getting a error telling that the output parameter is not specified.Can u help?

the code is here.....

public int UserAuthentication(String username, String password)
{
    SqlConnection conn = new SqlConnection("Data Source=CLEMATIS-11\\CLEMATISTECH; Initial Catalog=CUSTOMER360;User ID=sa;password=clematis1$");
    SqlCommand command = new SqlCommand("sp_Campaign_UserAuthentication", conn);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("@login_id", SqlDbType.VarChar, 50, "loginid"));
    command.Parameters.Add(new SqlParameter("@password",
        SqlDbType.VarChar,50,
        "password"));
    SqlParameter ret = command.Parameters.Add(" @result", SqlDbType.Int);
    ret.Direction = ParameterDirection.ReturnValue;
    command.Parameters["@login_id"].Value = username;
    command.Parameters["@password"].Value = password;
    conn.Open();
    command.ExecuteNonQuery();
    conn.Close();
    return (int)ret.Value;
}
A: 

I think the ReturnValue parameter has to be the first in the (edit) command parameter list.

Also, try querying the return parameter's value before closing the connection.

Ensure that your stored proc calls

RETURN (@SomeReturnValue) 

Lastly, try removing the leading space in your " @result" parameter name, just in case.

Neil Moss
@result is the return value and it is in the parameter list.And i also have tried to get the return value before closing the connection but the result is same.........
Alivia
Your code has the parameter as the third parameter added to the command's parameter list. Move it as the first.
Neil Moss
Can you please post the header of the stored procedure as well? Just the proc name and parameter list will do. I wonder if you've mixed up Output and ReturnValue parameter types.
Neil Moss
i found the solution its a store procedure so not a return type ParameterDirection.output; has to be used
Alivia