Testing if some value is null
<p>I have the following code, but i got a problem. Within my While, a have to test if r["Varandas"] is not null. In a specific imovel_id, the r["Varandas"] is null, but still passing through my code and then I got an exception error because can't parse to int the r["Varandas"] because is null, but why he pass through my first IF inside my While loop ?</p>

<pre><code>        string s = "SELECT * "
            + "FROM San_Imovel_Caracteristica "
            + "WHERE Imovel_Id = " + imovel_id + " ";

        SqlConnection c = new SqlConnection(conn.Con);
        SqlCommand cmd = new SqlCommand(s, c);
        c.Open();
        SqlDataReader r = cmd.ExecuteReader();

        while (r.Read())
        {
            if (r["Varandas"] != null)
            {
                if (Convert.ToInt32(r["Varandas"].ToString()) &gt; 0)
                {
                    XmlElement itemImovel1 = doc.CreateElement("itemImovel");
                    caracteristicasImovel.AppendChild(itemImovel1);
                    itemImovel1.InnerText = "varanda";
                }
            }
         }
</code></pre>
