title: SqlDataReader Best way to check for null values -sqlDataReader.IsDBNull vs DBNull.Value
body: <p>I want to retrieve decimal values from the database and I would like to know which is the recommended way to check for null values. </p>
  
  <p>I have seen on <a href="http://msdn.microsoft.com/en-us/library/system.dbnull.value.aspx" rel="nofollow noreferrer">MSDN - DBNull.Value Field </a> that this check is rarely used.</p>
  
  <p>Thus, is the <code>reader.IsDBNull</code> the best/most efficient way to check for nulls?</p>
  
  <p>I have created 2 sample methods:</p>
  
  <pre><code>public static decimal? GetNullableDecimal(SqlDataReader reader, string fieldName)
  {
      if (reader[fieldName] == DBNull.Value)
      {
          return null;
      }
      return (decimal)reader[fieldName];
  }
  
  public static decimal? GetNullableDecimal_2(SqlDataReader reader, string fieldName)
  {
      if (reader.IsDBNull(reader[fieldName]))
      {
           return null;
      }
      return (decimal)reader[fieldName];
  }
  </code></pre>
  
  <p>Most of the time the fields are going to be null.</p>
  
  <p>Thanks in advance!</p>