Solved

# manipulating dataset??

Posted on 2007-10-16
439 Views
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?

0
Question by:dkim18

LVL 9

Assisted Solution

/c# developer here tho :)
0

LVL 3

Accepted Solution

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

Author Comment

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

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

## Featured Post

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 & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, 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…