title: Return value using String result=Command.ExecuteScalar() error occurs when result returns null
body: <p>I want to fetch 1st row 1st cell value from database it works well with below code . But when there is no result found it throws Exception.</p>
  
  <p>How to handle with <code>DBNull</code> .<br>
  Should i change my query ? which return some value if theirs no record ?</p>
  
  <p><em>System.NullReferenceException: Object reference not set to an instance of an object.</em></p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>    public string absentDayNo(DateTime sdate, DateTime edate, string idemp)
      { 
         string result="0";
         string myQuery="select COUNT(idemp_atd) absentDayNo from td_atd where ";
         myQuery +=" absentdate_atd between '"+sdate+"' and '"+edate+" ";
         myQuery +=" and idemp_atd='"+idemp+"' group by idemp_atd ";
  
         SqlCommand cmd = new SqlCommand(myQuery, conn);
         conn.Open();
  //System.NullReferenceException occurs when their is no data/result
         string getValue = cmd.ExecuteScalar().ToString();
           if (getValue != null)
           {
              result = getValue.ToString();
           }
           conn.Close();
          return result;
      }
  </code></pre>