How to calculate the sum of the datatable column in asp.net?

后端 未结 9 1191
悲哀的现实
悲哀的现实 2020-11-27 04:15

I have a DataTable which has 5 columns:

  • ID
  • Name
  • Account Number
  • Branch
  • Amount

The DataTable contains 5 rows.

9条回答
  •  误落风尘
    2020-11-27 04:40

    Compute Sum of Column in Datatable , Works 100%

    lbl_TotaAmt.Text = MyDataTable.Compute("Sum(BalAmt)", "").ToString();
    

    if you want to have any conditions, use it like this

       lbl_TotaAmt.Text = MyDataTable.Compute("Sum(BalAmt)", "srno=1 or srno in(1,2)").ToString();
    

提交回复
热议问题