Philip Hendry's Blog

Return values from stored procedures using the Enterprise Library Data Access block

Sep 7, 2009 • Code, Enterprise Library • Less than a minute read

I’m not sure why I had so much trouble trying to do this… but because it did I think it’s worth a blog. Basically I was trying to return an int value from a stored procedure but couldn’t quite work out the syntax and was initially distracted by trying to use AddOutParameter() . However, the key was to use AddParameter() specifying the direction as ReturnValue :

db.AddParameter(cmd, "@return_value", DbType.Int32, ParameterDirection.ReturnValue, null, DataRowVersion.Default, null);

Then simply access the named parameter :

Convert.ToInt32(db.GetParameterValue(cmd, "@return_value"))
Post by: Philip Hendry