title: Why can I not cast a smallint from MSSQL to int like this: int x = (int)dt.Rows[x]["smallIntColumn"]
body: <p>Just looking for an explanation on this - the question pretty much explains it all but here's an bit extra:</p>
  
  <pre><code>//this line works OK
  int i = Convert.ToInt32(dt.Rows[x]["SmallintColumnName"]);
  
  //this line errors out
  int j = (int)dt.Rows[x]["SmallintColumnName"];
  </code></pre>
  
  <p>I find this strange but I guess there's a valid argument on why this is like it is.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:
  Hi @Damien_The_Unbeliever - it is an InvalidCastException - Specified cast is not valid.
  I guess I need to read up on boxing and unboxing. I assumed that both would work. 
  Now I have just tried:</p>
  
  <pre><code>int k = (Int32)r_dtAttribute.Rows[x]["CultureId"];
  </code></pre>
  
  <p>this also fails with the same InvalidCastException - so can anyone tell me what the actual difference is between</p>
  
  <pre><code>//fails
  int k = (Int32)r_dtAttribute.Rows[x]["CultureId"];
  </code></pre>
  
  <p>and</p>
  
  <pre><code>//works
  int i = Convert.ToInt32(dt.Rows[x]["SmallintColumnName"]);
  </code></pre>
  
  <p>What does the Convert.ToInt32 function do that just casting with (Int32) doesn't do?</p>
  
  <p>Thanks</p>