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

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

问题描述

我有一个有 5 列的数据表:

I have a DataTable which has 5 columns:

  • 身份证
  • 姓名
  • 帐号
  • 分支机构
  • 金额

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 中列的总和,请使用 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 = dataSet.Tables["YourTableName"];

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

在您的总金额标签中显示结果,如下所示:

Display the result in your Total Amount Label like so:

lblTotalAmount.Text = sumObject.ToString();

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

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