title: Isn't an Int64 equal to a long in C#?
body: <p>I have been playing around with SQL and databases in C# via <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlserverce.sqlceconnection%28v=vs.100%29.aspx" rel="noreferrer">SqlCeConnection</a>. I have been using <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executereader%28v=vs.110%29.aspx" rel="noreferrer">ExecuteReader</a> to read results and <a href="https://msdn.microsoft.com/en-us/library/ms187745.aspx" rel="noreferrer">BigInt</a> values for record IDs which are read into Longs.</p>
  
  <p>Today I have been playing with SQL statements that use COUNT based statements ('SELECT COUNT(*) FROM X') and have been using <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar%28v=vs.90%29.aspx" rel="noreferrer">ExecuteScalar</a> to read these single valued results.</p>
  
  <p>However, I ran into an issue. I can't seem to store the values into a Long data type, which I have been using up to now. I can store them into Int64's.</p>
  
  <p>I have been using BigInt for record IDs to get the maximum potential number of records.</p>
  
  <p>A BigInt 8 bytes therefore is an Int64. Isn't a Long equal to an Int64 as both are 64-bit signed integers?</p>
  
  <p>Therefore, why can't I cast an Int64 into a Long?</p>
  
  <pre><code>long recordCount =0;
  
  recordCount = (long)selectCommand.ExecuteScalar();
  </code></pre>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Specified cast is not valid.</p>
  </blockquote>
  
  <p>I can read a BigInt into a Long. It is not a problem.
  I can't read an SQL COUNT into a long.</p>
  
  <p>COUNT returns an Int (Int32), so the problem is in fact casting an Int32 into a long.</p>