manipulating dataset??

I have this data set like this

Date    Total_A Total_B   Total_C
2006-02   20      10            5    
2006-04     10       5            20
2006-10    5          25           15

I want to create a new dataset. Basically I am trying to calculate cumulativ count.
Date    Total_A Total_B   Total_C
2006-02   20      10            5    
2006-04   30      15            25
2006-10   35      40           40
Any idea I can do this easily.
This is what I am tried to do
-create a new dataset, newDs
-create a new table, newTable
-create a new row, newRow
-add row to table
-add table to dataset.

for each row in myDs.table(0).rows
    newRow = myDs.table(0).newRow

   for i = 0 to myDs.table(0).Rows.count
         if (i ==0) then
          newRow.Item(i) =  row.item(i)
          newRow.Item(i) =  row.item(i) + newRow.item(i-1)
          end if
  End for
End each

I haven't tried this yet.
Does this look right to you?

Who is Participating?
biodoomsConnect With a Mentor Commented:

I think I can write you something wich does what you wanted. Hope its usefull.

DataTable newTable = new DataTable();
newTable.Columns.Add(new DataColumn("Item1", System.Type.GetType("System.String")));
newTable.Columns.Add(new DataColumn("Item2", System.Type.GetType("System.String")));
newTable.Columns.Add(new DataColumn("Item3", System.Type.GetType("System.String")));

DataRow dr = dt.NewRow();

Int Counter;

foreach (DataRow dataRow in Datatable.Rows)
    If (Session["Item1"] != Null)
        Counter = Convert.ToInt(Session["Item1"]) + Convert.ToInt(dataRow.ItemArray.GetValue(1));
        dr["Item1"] = Convert.ToString();
        dr["Item1"] = dataRow.ItemArray.GetValue(1).ToString();
    If (Session["Item2"] != Null)
        Counter = Convert.ToInt(Session["Item2"]) + Convert.ToInt(dataRow.ItemArray.GetValue(2));
        dr["Item1"] = Convert.ToString();
        dr["Item2"] = dataRow.ItemArray.GetValue(2).ToString();
    If (Session["Item3"] != Null)
        Counter = Convert.ToInt(Session["Item3"]) + Convert.ToInt(dataRow.ItemArray.GetValue(3));
        dr["Item1"] = Convert.ToString();
        dr["Item3"] = dataRow.ItemArray.GetValue(3).ToString();

    Session["Item1"] = dataRow.ItemArray.GetValue(1).ToString();
    Session["Item2"] = dataRow.ItemArray.GetValue(2).ToString();
    Session["Item3"] = dataRow.ItemArray.GetValue(3).ToString();

This basicly checks if there is a session. If there is a session then the new rows data is first row + session. else its just the Default row(like in the first row). And adds that to a new table. Well you can costum it as you wish but i hope it helps you a bit.

With kind regards,

Kevin Hendricks
Type25Connect With a Mentor Commented:
Yep looks about right.

/c# developer here tho :)
dkim18Author Commented:
What's this Session agaiN?
Why are you using that?
Thanks much
Cause the loop takes a row after another and I want the previous row data and the present row data. so I session it and use it if its available.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.