0
DataTable dt1 = new DAL.DALHelper().getData(cmd);

if (dt.Rows.Count > 0)
{
    int x = 0;
    foreach (DataRow r in dt.Rows)
    {
        x += Convert.ToInt32(r["amount"]);
    }
    lblExpense.Text = x.ToString();
}

I am trying to SUM values. but there is so may NULL value so how I can total it? And my value is string value. showing this error(Object cannot be cast from DBNull to other types.)

1 Answers1

0

Check if r["amount"] != System.DBNull.Value. then add in sum.

M_Idrees
  • 2,080
  • 2
  • 23
  • 53