Get total of a datacolumn RRS feed

  • Question

  • Hi, I want to get the totals of a datacolumn in a datatable and then display it on a label, how could I do it? Thanks for your help.
    Tuesday, June 19, 2007 9:55 PM

All replies

  • Hi


    I am not totally sure of what you mean but if for example you wanted to get the SUM of a column within a DataTable then you could use the DataTable's Compute method to achieve this.




    Tuesday, June 19, 2007 10:54 PM
  • hi,

    try this out,

    int i = datatable.columns.count;

    label.text = i.tostring();

    Prasenna. K

    Wednesday, June 20, 2007 5:11 AM
  • I dont think thats what the person wanted to know, guess what you are saying returns the number of columns in the datatable. I agree that the soln is the compute method.


    For example if you have a datatable ("Payments") where u have payments made by a customer and you want to find the sum of all payments made by a particular customer.


    Assuming a datatable "Payments", A column called "Total" storing amt paid. And a customer with CustID = 67.


    First declare an object


     Dim TotalsObject As Object
        TotalsObject = Payments.Compute("Sum(Total)", "CustID = 67")

    Wednesday, June 20, 2007 6:44 AM