Chris
Chris

Reputation: 3129

How to get the output of a stored procedure?

I was wondering how to get the output of a stored procedure without doing it the long way, the long way I am referring to is..

SqlParameter productidparam;
productidParam = cmAddProduct.Parameters.Add("@TheProductID", SqlDbType.Int);
productidParam.Direction = ParameterDirection.Output;

instead I am trying to get the output with overloading like this...

cm.Parameters.Add(new SqlParameter("@TheProductID", SqlDbType.Int)).Direction = ParameterDirection.Output;

with the long way I know I can get the proc output with

string myproductidparam;
myproductidparam = productidparam.Value.ToString();

but how do I get the output with the shorter statement?

Thanks

Upvotes: 1

Views: 80

Answers (1)

D Stanley
D Stanley

Reputation: 152644

You could pull the parameter from the command by name:

myproductidparam = Convert.ToInt32(cm.Parameters["@TheProductID"].Value);

Upvotes: 3

Related Questions