DataTable da = CommonBLL.GetList("*", "sys_dict", "IfState=1 and DictTypeId=14"); string strField = "CACCNUM as 账号账号,Loannumber as 借据号,BILLDATE as 借款时间,CAName as 借款人姓名,CPOSITION as 质押商品房位置,LoanAmount as 借款总额,"; for (int i = 0; i < da.Rows.Count; i++) { strField += " case when xqName ='" + da.Rows[i]["DictName"].ToString() + "' then LoanAmount else null end as " + da.Rows[i]["DictName"].ToString() + "_借款总额,"; } strField += "Rateval as 年利率,Endratedata as 到期时间,CTEL 借款人固定电话,CMOBILE as 借款人手机号,CSSNUMBER as 身份证号,CADDRESS as 住址,CWORK as 所在单位,Realtor as 售楼员,Proportion as 首付比例,RepayAmountSum as 己还本金合计,"; for (int i = 0; i < da.Rows.Count; i++) { strField += " case when xqName ='" + da.Rows[i]["DictName"].ToString() + "' then RepayAmountSum else null end as " + da.Rows[i]["DictName"].ToString() + "_己还本金合计,"; } strField += "RepayRateSum as 已清利息合计,"; for (int i = 0; i < da.Rows.Count; i++) { strField += " case when xqName ='" + da.Rows[i]["DictName"].ToString() + "' then RepayRateSum else null end as " + da.Rows[i]["DictName"].ToString() + "_已清利息合计,"; } strField += "RepaySum as 本息合计,SurplusSum as 剩余本金合计 ,"; for (int i = 0; i < da.Rows.Count; i++) { strField += " case when xqName ='" + da.Rows[i]["DictName"].ToString() + "' then SurplusSum else null end as " + da.Rows[i]["DictName"].ToString() + "_剩余本金合计,"; } strField += "Repay as 已还清"; DataTable dt = JZCard.BLL.CommonBLL.GetList(strField, "v_finance_billloan_list", _strWhere); decimal JkHj = Commons.ParseDecimalValue(dt.Compute("sum(借款总额)", "")); decimal YHBJHJ = Commons.ParseDecimalValue(dt.Compute("sum(己还本金合计)", "")); decimal YQLXHJ = Commons.ParseDecimalValue(dt.Compute("sum(已清利息合计)", "")); decimal BXHJ = Commons.ParseDecimalValue(dt.Compute("sum(本息合计)", "")); decimal SYBXHJ = Commons.ParseDecimalValue(dt.Compute("sum(剩余本金合计)", "")); DataRow dr = dt.NewRow(); dr["账号账号"] = "合计"; dr["借款总额"] = JkHj; dr["己还本金合计"] = YHBJHJ; dr["已清利息合计"] = YQLXHJ; dr["本息合计"] = BXHJ; dr["剩余本金合计"] = SYBXHJ; dt.Rows.Add(dr); // c#如何设置DataGridView的自动创建列 this.dg_BillLoanList.AutoGenerateColumns = true; this.dg_BillLoanList.DataSource = dt;