下面的代码似乎有什么问题?我认为数据库中有空值,如何对包含空值的列求和?
int Total_QtyinHand = 0;
int Total_QtyAllocated = 0;
int Total_QtyinStock = 0;
int Total_QtyUpcoming = 0;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// VVV --- Exception happens on the line below --- VVV
Total_QtyinHand += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "QuantityonHand"));
Total_QtyAllocated += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Allocated_Quantity"));
Total_QtyinStock += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Qty_in_Stock"));
Total_QtyUpcoming += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "UpcomingStock"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[3].Text = "Total Qty";
e.Row.Cells[3].Font.Bold = true;
e.Row.Cells[4].Text = Total_QtyinHand.ToString();
e.Row.Cells[4].Font.Bold = true;
e.Row.Cells[5].Text = Total_QtyAllocated.ToString();
e.Row.Cells[5].Font.Bold = true;
e.Row.Cells[6].Text = Total_QtyUpcoming.ToString();
e.Row.Cells[6].Font.Bold = true;
}
}