title: casting ExecuteScalar() result c#
body: <p>why would this work</p>
  
  <pre><code>int collectionCharge = (int)cmdCheck.ExecuteScalar();
  </code></pre>
  
  <p>but this produces an exception</p>
  
  <pre><code>double collectionCharge = (double)cmdCheck.ExecuteScalar();
  </code></pre>
  
  <blockquote>
    <p>System.InvalidCastException: Specified cast is not valid.</p>
  </blockquote>
  
  <p>why would it not be valid?</p>
  
  <p><strong>EDIT</strong>
  I am trying to simply return a single result from a query, that gets the price of some freight. So I can't turn this into an <code>int</code> because it must have decimals, hence trying to cast to a <code>double</code>. I am still learning asp.net so if there's a better way to achieve this, please do point me in the right direction :)</p>
  
  <p><strong>EDIT 2</strong>
  the full code with SQL...</p>
  
  <pre><code>using (SqlCommand cmdCheck = new SqlCommand("SELECT FREIGHT_PRICE FROM FREIGHT_QUOTER_BELNL_NEW WHERE CUSTOMER_NO = @CUSTOMER_NO AND COUNTRY = @COUNTRY AND ROUND(WEIGHT_FROM,0) &lt; @WEIGHT AND ROUND(WEIGHT_TO,0) &gt;= @WEIGHT AND SHIPVIA = '48';", connection))
                  {
                      double collectionCharge = (double)cmdCheck.ExecuteScalar();
                      FreightAmount = collectionCharge;
                  }
  </code></pre>