title: "Object cannot be cast from DBNull to other types"
body: <p>When my website gets to the following bit of code, it falls down with an exception as follows:</p>
  
  <blockquote>
    <p>System.InvalidCastException: Object cannot be cast from DBNull to other types.</p>
  </blockquote>
  
  <p>For the interests of brevity, I'm showing only the relevant code (it's a 4000+ LOC file I've been given).</p>
  
  <pre><code>if (dr["STAGE"] is DBNull)
  {
      dto.Stage = 1; // This is the line throwing the exception, according to stack trace
  }
  else
  {
      dto.Stage = Convert.ToInt32(dr["STAGE"]);
  }
  </code></pre>
  
  <p>Here, <code>dr</code> is a DataRow object that is the result of a query to a database, <code>dto</code> is a basic class that just holds some properties, of which <code>dto.Stage</code> is an <code>int</code> member.</p>
  
  <p>I've looked at other questions with the same error message, but most of them seem to suggest "Check if it's DBNull", which I'm already doing.</p>
  
  <p>So can someone suggest a solution?</p>