title: Specified cast is not valid error using C#
body: <p>I am trying to store a select statement result in C# variable but getting this error </p>
  
  <blockquote>
    <p>"Specified cast is not valid"</p>
  </blockquote>
  
  <p>when i run it.  I am not sure how to resolve it please help</p>
  
  <pre><code>SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
  
          SqlCommand cmd1 = new SqlCommand("select cast(round(sum(CAST(AvgNumbers AS numeric(12,2))),2) as decimal(12,2)) AS [Average Days] from MainTable ", con1);
  
          cmd1.Connection = con1;
          con1.Open();
          Int32 result = (Int32)cmd1.ExecuteScalar();
          con1.Close();
  </code></pre>