在 datagridview 中 修改数据后,再从新累加数据,然后插入到数据库中。

在 datagridview 中 修改数据后,再从新累加数据,然后插入到数据库中。


用的for循环,先以行循环相加,然后在列循环相加,把数据放到table 中

  DataTable dtable = new DataTable();
                    DataTable dt = new DataTable();
                    dt.Columns.Add("a", typeof(decimal));
                    dt.Columns.Add("b", typeof(decimal));
                    dt.Columns.Add("c", typeof(decimal));
                    dt.Columns.Add("d", typeof(decimal));
                    dt.Columns.Add("e", typeof(decimal));
                    dt.Columns.Add("f", typeof(decimal));
                    dt.Columns.Add("h", typeof(decimal));
                    dt.Columns.Add("j", typeof(decimal));
                    for (int i = 1; i < dataGV.Rows.Count; i++)
                    {
                        int sum = 0;
                        for (int j = 2; j < dataGV.ColumnCount; j++)
                        {
                            sum += int.Parse(dataGV.Rows[i].Cells[j].Value.ToString());
                        }
                        dataGV.Rows[i].Cells[0].Value  = sum;
                        dataGV.Rows[i].Cells[1].Value = sum;
                    }
                    for (int k = 0; k < dataGV.ColumnCount; k++)
                    {
                        int lsum = 0;
                        for (int h = 1; h < dataGV.Rows.Count; h++)
                        {
                            lsum += int.Parse(dataGV.Rows[h].Cells[k].Value.ToString());
                        }
                        dataGV.Rows[0].Cells[k].Value  = lsum;
                    }

 

                    for (int i = 0; i < dataGV.Rows.Count; i++)
                    {
                        DataRow dr = dt.NewRow();
                        dr["a"] = dataGV.Rows[i].Cells[0].Value.ToString();
                        dr["b"] = dataGV.Rows[i].Cells[1].Value.ToString();
                        dr["c"] = dataGV.Rows[i].Cells[2].Value.ToString();
                        dr["d"] = dataGV.Rows[i].Cells[3].Value.ToString();
                        dr["e"] = dataGV.Rows[i].Cells[4].Value.ToString();
                        dr["f"] = dataGV.Rows[i].Cells[5].Value.ToString();
                        dr["h"] = dataGV.Rows[i].Cells[6].Value.ToString();
                        dr["j"] = dataGV.Rows[i].Cells[7].Value.ToString();
                        dt.Rows.Add(dr);
                    }

转载于:https://www.cnblogs.com/08netsx/archive/2010/08/25/1808484.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值