title: How to check DBNull value in Linq query results
body: <p>I am using the below code and trying to group by Currency and Code. After this I am trying to loop through the result set.</p>
  
  <p>But the issue is while looping through the results, at the end I am getting the below exception on the for each statement:</p>
  
  <p><strong>Object cannot be cast from DBNull to other types.</strong></p>
  
  <pre><code>    DataTable dt = new DataTable();
  
      var result = from r in dt.AsEnumerable()
                 result r by new
                 {
                      currency = r.Field&lt;String&gt;("CURRENCY"),
                      Code = r.Field&lt;String&gt;("CODE")
                 }
                into grp
                select new
                {
                     currency = grp.Key.currency,
                     Code = grp.Key.Code,
                     amount = grp.Sum(x =&gt; Convert.ToDouble(x["AMOUNT"]))
                };
  
      foreach (var obj in result)
      {
        String sCurr =obj.currency;
        String Code = obj.Code;
        string amount= obj.amount.ToString());
      }
  </code></pre>
  
  <p>Please help me to resolve this issue.</p>