title: Why does this cast from short to int fail?
body: <p>We have some code that archives data from a Microsoft Access database into a MS SQL Server database.  Assuming we have a data reader already populated from the Access table and we are adding a parameter to a SqlCommand in preparation for the insert, we have a typecast that is failing.  Here is the code:</p>
  
  <pre><code>oSqlServerDbCmd_ForInsert.Parameters.AddWithValue("@Duration",
       (int) oReader["Duration"]);
  </code></pre>
  
  <p>The field from the oReader is actually an Access Integer, which is a short in C#.  If we cast to a short here there is no problem.  However, if we cast to an int the code throws an InvalidCastException.  I may be misreading this from the <a href="http://msdn.microsoft.com/en-us/library/ybs77ex4%28v=vs.71%29.aspx">MSDN documentation</a>:</p>
  
  <p>"There is a predefined implicit conversion from short to int, long, float, double, or decimal."</p>
  
  <p>...but it sounds like this should work (my reasoning being, if an implicit conversion is defined why would an explicit typecast not work?).  I realize the cast is not even necessary because AddWithValue accepts an object, so we have actually removed the cast from our code, but I would love to see an explanation as to why this cast was failing just in case we run into something like this in the future.</p>