manipulating dataset??

Posted on 2007-10-16
Last Modified: 2012-06-27
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?

Question by:dkim18
    LVL 9

    Assisted Solution

    Yep looks about right.

    /c# developer here tho :)
    LVL 3

    Accepted Solution


    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

    Author Comment

    What's this Session agaiN?
    Why are you using that?
    Thanks much
    LVL 3

    Expert Comment

    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.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now