0

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 ?

1 Answer 1

1

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

cmd.Parameters.Add(sqlParameterRet );

before

cmd.ExecuteNonQuery();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.