title: Return Parameter From SQL Query
body: <p>I am trying to run a sql stored procedure and return a value from the query.  My syntax throws the error of:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.Data.SqlClient.SqlParameter' to 'decimal'</p>
  </blockquote>
  
  <p>This is my syntax, what should I alter in order to have this run properly?</p>
  
  <pre><code>public Decimal ReturnValueFromQuery(string connectionString, string sqlQuery, int blah, DateTime d1, DateTime d2)
  {
  string cs = System.Configuration.ConfigurationManager.AppSettings[connectionString].ToString();
  try
  {
      using (SqlConnection conn = new SqlConnection(cs))
      using (SqlCommand cmd = conn.CreateCommand())
      {
          cmd.CommandText = sqlQuery;
          cmd.Connection = conn;
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.Add("@blah", SqlDbType.Int).Value = blah;
          cmd.Parameters.Add("@startDate", SqlDbType.Date).Value = d1;
          cmd.Parameters.Add("@endDate", SqlDbType.Date).Value = d2;
          var returnParameter = cmd.Parameters.Add("@ReturnVal", SqlDbType.Int);
          returnParameter.Direction = ParameterDirection.ReturnValue;
          conn.Open();
          cmd.ExecuteNonQuery();
          return returnParameter;
      }
  }
  catch { }
  }
  </code></pre>