# 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

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)
else
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?

Commented:
Hey,

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

DataTable newTable = new DataTable();

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();
}
else
{
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();
}
else
{
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();
}
else
{
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
0

Commented:

/c# developer here tho :)
0

Author Commented:
What's this Session agaiN?
Why are you using that?
Thanks much
0

Commented:
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.
0
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.