using (DataCommand dc = new DataCommand())
{
string sqlWhere = "";
dc.CommandText = @"
select zcry,
total_sum=(select COUNT(b.TableID) from table2 b
where a.zcry=b.create_user
and b.CreateTime>@StartDt and b.CreateTime<@EndDt
) ,
total_dfk=(select COUNT(b.TableID) from table3 b
where a.zcry=b.jlr and b.wgcl='数量1'
and b.CreateTime>@StartDt and b.CreateTime<@EndDt
) ,
total_gr=(select COUNT(b.TableID) from table3 b
where a.zcry=b.jlr and b.wgcl='数量2'
and b.CreateTime>@StartDt and b.CreateTime<@EndDt
) ,
total_zq=(select COUNT(b.TableID) from table3 b
where a.zcry=b.jlr and b.wgcl='数量3'
and b.CreateTime>@StartDt and b.CreateTime<@EndDt
) ,
total_hwb=(select COUNT(b.TableID) from table3 b
where a.zcry=b.jlr and b.wgcl='数量4'
and b.CreateTime>@StartDt and b.CreateTime<@EndDt
)
form table1 a where 1=1 ";
dc.CommandText += sqlWhere + " group by zcry";
dc.AddParameter("@StartDt", DbType.DateTime).Value = DateTime.Parse(startDP.Text);
dc.AddParameter("@EndDt", DbType.DateTime).Value = DateTime.Parse(endDP.Text).AddDays(1);
DataTable dt = dc.ExecuteDataTable();
int total_sum=Convert.ToInt32(dt.Compute("sum(total_sum)", ""));
DataRow dr = dt.NewRow();
dr[0]="合计";
dr[1]=dt.Compute("sum(total_sum)", "");
dr[2]=dt.Compute("sum(total_dfk)", "");
dr[3]=dt.Compute("sum(total_gr)", "");
dr[4]=dt.Compute("sum(total_zq)", "");
dr[5]=dt.Compute("sum(total_hwb)", "");
dt.Rows.Add(dr);
grid1.DataSource = dt;
grid1.DataBind();
}