计算数据集中的列值 [英] Count the column Values in a DataSet

查看:119
本文介绍了计算数据集中的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个数据集,其中一列是计数".
在那个col记录是这样的.

Hi,


I have a Dataset, in that one column is "Count".
In that col records are like this.

Count
10
2
5
1
12



我想要该列的总和,例如(10 + 2 + 5 + 1 + 12).如果我添加另一条记录,则意味着该记录也会自动计数.
我想在GridView的页脚模板中显示该SUM.

谁能帮我怎么做

在此先感谢



I want Total sum of that column like (10+2+5+1+12).If i add another record means that record also counted automatically.
I want to display that SUM in footer Template of my GridView.

can anyone help me how to do this

Thanks in advance

推荐答案

这是一种实现方法

Here is one way to do it

object objSum;
objSum = YourDataSet.Tables[0].Compute("Sum(Count)", "");
Your_Footer = (int)objSum;



您可以参考下面的链接以获取更多信息
DataTable.Compute方法 [ ^ ]

这是一些线程,显示了如何在gridview页脚中显示总计.
Gridview的总和列应显示在Gridview底部的最后一行中 [如何计算GridView的页脚? [如何显示GridView页脚 [ DataGridView上的总行脚数 [如何显示GridView页脚 [



You can refer the below link for more information
DataTable.Compute Method[^]

Here are some threads showing how to display total in gridview footer.
Sum of an Gridview Column should be shown in the last row of Bottom in Gridview[^]
how to calculate total price in the footer of gridview?[^]
How to display GridView Footer[^]
Total Row Footer on DataGridView[^]
How to display GridView Footer[^]



试试这个:
Hi,
Try this:
var sum = table.AsEnumerable().Sum(x=>x.Field<int>("Count"));
//Where count is your Column name and table is your table of dataset</int>





--Amit





--Amit


DataTable table = YourDataSet.Table[0];
int count = 0;
foreach(DataRow dr in table.Rows)
{
    count+= Convert.ToInt32(dr["Count"]);
}

Your_Footer = count;



希望对您有所帮助.



Hope it helps.


这篇关于计算数据集中的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆