The other response shows this, but essentially you just need to create a SqlParameter, add it to the SqlCommand's Parameter's collection, and set the ParameterDirection to Output. Then execute the stored procedure and get the value of the parameter.
Using your code sample:
public bool Blah()
{
using (SqlConnection conn = new SqlConnection())
{
SqlCommand cmd = new SqlCommand("sproc", conn);
cmd.CommandType = CommandType.StoredProcedure;
// add parameters
cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int, int.MaxValue, ParameterDirection.Output));
conn.Open();
// *** GRAB output paramter here, how?????????
cmd.ExecuteNonQuery();
int id = cmd.Parameters["@ID"].Value;
conn.Close();
}
}
Be careful when getting the Parameters[].Value, since the type needs to match what you're declaring it as when you create the SqlParameter. And if you're going to just output it to the console, you may just be using Parameters["@Param"].Value.ToString() if it's some other type. This will bite you more often if you're not using the SQL Provider (i.e. using Oracle or some other provider, where the types are non-.NET native).