Cumulative (Running) Total Column in DataSet RRS feed

  • General discussion

  • Hi.

    I have a Dataset table with just One Column "Amount"








    I want to add a column called cumulative


    Amount   Cumulative

    1               1

    2               3

    3               6

    4               10

    5               15


    How To Do It in a Data Set.




    I Love Microsoft
    Sunday, November 7, 2010 5:07 PM

All replies

  • Hello,

    Please take a look at the following documentation about adding columns to DataTable:

    In your case, please try the following code snippet:

    DataTable dt = ds.Tables[0];
    DataColumn dc = new DataColumn("Cumulative", typeof(Int32));
    dt.Rows[0][1] = 1;
    dt.Rows[1][1] = 3;
    dt.Rows[2][1] = 6;
    dt.Rows[3][1] = 10;
    dt.Rows[4][1] = 15;

    Hope this helps

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Tuesday, November 9, 2010 6:37 AM
  • Hi Roahn..

    Thanks for your time.

    My Question Is : What is the Expression (Or other way) to calculate running Total column.

    Threre are millions of rows. What I gave was just a Sample to make my Question Clear.


    I Love Microsoft
    Tuesday, November 9, 2010 6:18 PM