Question

I have a definiton of procedure

public int Add_Nastavenie(out int typNastav, int nastavID, string hod)
{
    ResetParameters();
    cmd.CommandText = "add_Nastav";
    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter sqlParameter;

    var sqlParameterOut = new SqlParameter("@TypNastav", SqlDbType.Int);
    sqlParameterOut.Direction = ParameterDirection.Output;


    sqlParameter = new SqlParameter("@NastavenieID", SqlDbType.Int);
    sqlParameter.Direction = ParameterDirection.Input;
    sqlParameter.Value = nastavID;
    cmd.Parameters.Add(sqlParameter);

    sqlParameter = new SqlParameter("@Hodnota", SqlDbType.NVarChar, 100);
    sqlParameter.Direction = ParameterDirection.Input;
    sqlParameter.Value = hod;
    cmd.Parameters.Add(sqlParameter);

    var sqlParameterRet = new SqlParameter("retValue", SqlDbType.Int);
    sqlParameterRet.Direction = ParameterDirection.ReturnValue;

    cmd.ExecuteNonQuery();
    typNastav = (int)sqlParameterOut.Value;
    return (int)cmd.Parameters["retvalue"].Value;

}

I call this procedure like this :

 dataConnector.Add_Nastavenie(out typNastav,nastavID,hod); 

It's show error :

sql parameter with ParameterName 'retvalue' is not contained by this sqlParameterCollection

How can i fix it ?

Was it helpful?

Solution

You are getting this because you haven't added the return parameter to command. you missed this

cmd.Parameters.Add(sqlParameterRet );

before

cmd.ExecuteNonQuery();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top