Mox Shah
Mox Shah

Reputation: 3015

Stored Procedure Output parameter returns null

SqlParameter[] par1 = new SqlParameter[4];

par1[0] = new SqlParameter("@prefix", "TIN-CMP-");
par1[1] = new SqlParameter("@codeLength", "17");
par1[2] = new SqlParameter("@LastCode", "");
par1[3] = new SqlParameter("@retVal", SqlDbType.VarChar, 20);
par1[3].Direction = ParameterDirection.Output;
var data = SqlHelper.ExecuteNonQuery(this.ConnectionString, "Proc_GenerateID", par1);

it doesn't throw any exception but returns null value, Even procedure working fine in SSMS

Upvotes: 0

Views: 1342

Answers (1)

AdaTheDev
AdaTheDev

Reputation: 147224

Make sure SqlHelper.ExecuteQuery is reading the output parameter value after executing the sproc.

e.g.

yourCommand.ExecuteNonQuery();
string retVal = yourCommand.Parameters["@retVal"].Value;

Upvotes: 1

Related Questions