如何计算在asp.net数据表列的总和? [英] How to calculate the sum of the datatable column in asp.net?

查看:97
本文介绍了如何计算在asp.net数据表列的总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataTable,其中有5列:

I have a DataTable which has 5 columns:


  • ID

  • 名称

  • 帐号


  • 金额

该DataTable包含5行。

The DataTable contains 5 rows.

我如何能显示金额列在一个标签控件为合计金额之和?

How can I show the sum of the Amount Column in a Label Control as "Total Amount"?

推荐答案

要计算一个DataTable使用<一列的总和href=\"http://msdn.microsoft.com/en-us/library/system.data.datatable.compute.aspx\">DataTable.Compute方法。

To calculate the sum of a column in a DataTable use the DataTable.Compute method.

从链接的MSDN文章使用示例:

Example of usage from the linked MSDN article:

DataTable table;
table = dataSet.Tables["YourTableName"];

// Declare an object variable.
object sumObject;
sumObject = table.Compute("Sum(Amount)", "");

结果显示在您的总金额标签,像这样:

Display the result in your Total Amount Label like so:

lblTotalAmount.Text = sumObject.ToString();

这篇关于如何计算在asp.net数据表列的总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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