Dattemp表Dr和Cr中有两列。我需要结果和(dr)-sum(cr)和datdetail表的开放平衡列中的dattemp上的where子句
for (int i = 0; i < datDetail.Rows.Count; i++)
{
datDetail.Rows[i]["Opening Balance"] = Convert.ToDouble(DatTemp.AsEnumerable().Where(r => r.Field<int>("Identity ID") == Convert.ToInt32(datDetail.Rows[i]["Identity ID"]) && (r.Field<DateTime>("Date") <= Convert.ToDateTime(TxtFromDate.Text.Trim()))).Sum(r => r.Field<decimal>("CR")) - DatTemp.AsEnumerable().Sum(r => r.Field<decimal>("DR"))).ToString("00.00");
datDetail.Rows[i]["Clossing Balance"] = Convert.ToDouble(DatTemp.AsEnumerable().Where(r => r.Field<int>("Identity ID") == Convert.ToInt32(datDetail.Rows[i]["Identity ID"]) && (r.Field<DateTime>("Date") <= Convert.ToDateTime(TxtToDate.Text.Trim()))).Sum(r => r.Field<decimal>("CR")) - DatTemp.AsEnumerable().Sum(r => r.Field<decimal>("DR"))).ToString("00.00");
}
GridDetails.DataSource = datDetail;
GridDetails.DataBind();
答案 0 :(得分:0)
您可以尝试以下内容:
var openBal = DatTemp.Compute("Sum(OpeningBalance)", "");
var closeBal = DatTemp.Compute("Sum(ClosingBalance)", "");
var difference = Math.Abs(openBal - closeBal);//you may need to cast here