|
发表于 2020-1-24 10:00:01
|
显示全部楼层
可以参考一下!
DataSet ds;
ds = dbconn.selectSQL();
try
{
ds.Tables[0].Columns[0].ColumnName = "序号";
ds.Tables[0].Columns[1].ColumnName = "列1";
ds.Tables[0].Columns[2].ColumnName = "列2";
ds.Tables[0].Columns[3].ColumnName = "列3";
int iNum1 = 0;
int iNum2 = 0;
int iNum3 = 0;
for (int i = 0; i < dsTypes.Tables[0].Rows.Count; i++)
{
iNum1 = iNum1 + int.Parse(ds.Tables[0].Rows[i][1].ToString());
iNum2 = iNum2 + int.Parse(ds.Tables[0].Rows[i][2].ToString());
iNum3 = iNum3 + int.Parse(ds.Tables[0].Rows[i][3].ToString());
}
DataRow dr = ds.Tables[0].NewRow();
dr["序号"] = "合计";
dr["列1"] = iNum1;
dr["列2"] = iNum2;
dr["列3"] = iNum3;
ds.Tables[0].Rows.Add(dr);
this.dataGridView1.DataSource = ds.Tables[0].DefaultView; |
|