如何在C#中向datagridview添加数据 [英] how to add data to datagridview in c#
本文介绍了如何在C#中向datagridview添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,我实际上想向datagrid视图添加数据,我现在通过在表nd处使用数据集表对象添加数据,以便在datagrid视图中添加总计的总和,这意味着我想向其中添加新行原始的gridview将向您显示上述金额的总和.我使用了以下代码
hi friends I want to add data to datagrid view actually i have added data by using dataset table object now at the nd of table i wnat to add totoal sum of ammount in datagrid view that mean i want to append a new row to original gridview which will show you sum of above ammounts. i have used following code
fromdate = dateTimePicker1.Value;
todate = dateTimePicker2.Value;
string fd = fromdate.Month + "-" + fromdate.Day + "-" + fromdate.Year, td = todate.Month + "-" + todate.Day + "-" + todate.Year;
con.Close();
con.Open();
string cons = "SELECT Registration_ID,Name,VersionNo,Class,TotaltobePaid,PaidFees,BalanceFees FROM FeesCollection WHERE PaymentDate BETWEEN CAST('" + fd + "' AS DATE) AND CAST('" + td + "' AS DATE)";
SqlCommand cmd = new SqlCommand(cons,con);
SqlDataAdapter sda = new SqlDataAdapter(cons, con);
DataSet ds = new DataSet();
sda.Fill(ds, "FeesCollection");
SqlDataReader sdr;
sdr = cmd.ExecuteReader();
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Rows[ds.Tables[0].Rows.Count].HeaderCell.Value = "Total:";
con.Close();
它显示了我现在想要的所有数据,如何在网格视图的末尾添加新行,以便向我显示平衡的总和,请帮助我.
it shows me all data which i want now how to add new row at the end of grid view so it will show me sum of balence please help me.
推荐答案
请参阅以下帖子中的示例:
http://stackoverflow.com/questions/3779729/how-i-can-show-the-sum-of-a-datagridview列 [
see example in the following post:
http://stackoverflow.com/questions/3779729/how-i-can-show-the-sum-of-in-a-datagridview-column[^]
这篇关于如何在C#中向datagridview添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文