c#在dataGridView中增加一列并赋值



                string selpeople = "select 姓名,工号,区域所属,所属部门,入住时间,退宿时间 from 员工信息表";
                pub.xsdgv(selpeople, dataGridView11);

                DataTable dt = (DataTable)dataGridView11.DataSource;
                dt.Columns.Add("住宿费用");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DateTime dtruzhu = Convert.ToDateTime(dt.Rows[i][5]);
                    DateTime dttuisu = Convert.ToDateTime(dt.Rows[i][6]);
                    double zhusufeiyong=0.02;
                    //计算住宿费用

                    dt.Rows[i]["住宿费用"] = zhusufeiyong;

                }
                dataGridView11.DataSource = dt;

你可能感兴趣的:(C#实践问题汇总)