Unexpected behavior between String.IsNullOrEmpty and DBNull.Value
<p>I have the following query:</p>

<pre><code>public static string GetCustomerName(string customerNo)
{
   string query = "query to get customer";
   var myConn= new MYConnection();
   using (SqlConnection con = new SqlConnection(myConn.MYConnectionString))
   {
       con.Open();
       SqlCommand cmd = new SqlCommand(query, con);
       cmd.Parameters.Add("@customerNo", SqlDbType.NVarChar).Value = customerNo;
       object result = cmd.ExecuteScalar();
       return result == DBNull.Value ? String.Empty : (string)result;
   }

}
</code></pre>

<p>I'm calling the method above like this:</p>

<pre><code>string customerName = GetCustomerName(CustomerID);

if (customerName.Contains(Constants.Company.CompanyName))
{

    Additional Logic...
}
</code></pre>

<p>However, I'm getting a Object Reference Null error if my method doesn't return a customer name. I would think that the GetCustomer method would return an empty string. </p>

<p>If I change the call to get the CustomerName to below, it works perfectly.</p>

<pre><code>string customerName = GetCustomerName(emailAndSTCodeInfo.CustomerID);
if (String.IsNullOrEmpty(customerName))
{
    customerName = "";
}
if (customerName.Contains(Constants.Chase.ACCOUNT_NAME))
{
    Additional Logic
}
</code></pre>

<p>So, my question is, what would be the proper way of handling this if my GetCustomer method doesn't find a record and returns null. I'm currently using the working code above but it seems like a hack or something.</p>

<p>Any help would be greatly appreciated.</p>
