Reputation: 1
I have this huge query that returns a datatable like this:
m | m | m| mo...|12 |total |increased
10 | 2 | 3| 5 |20 |40 | 100%
30 | 6 | 9| 15 |60 |120 | 300%
except the column increased
does not exist.
The point is, I have to make it exist. All I have are the data in the months and its sum (total). I need to make a column that gets whatever sum is in a row, compare to the previous sum, and say how much it has increased (% based)
using postgresql, .net and c# Any help?
edit: It's just a Datatable Function_that_queries_the_SQL_string(); Then in the page displaying the table i have an <asp:GridView> with a bunch of <asp:BoundField> to the columns in the table
. But I have no idea if to make the increased column I have to change the query, or just get the data somehow from the Datatable and use c# to do the math
Upvotes: 0
Views: 296
Reputation: 1
Well, I used a mix of Blam's and Crono's answers. I created another column using the DataColumn. Then I looped through the rows in the previous column using the DataRows, did some algebrae, typecasted the object to a bigint and voilá. Thanks a lot guys.
Upvotes: 0
Reputation: 93
DataTable table = GetTable();
foreach (Row row in table.Rows)
{
row.SetField("Increased", valueA/valueB);
}
Upvotes: 1
Reputation: 10478
I think your best option is to calculate the value on client side by looping through your records. For each occurence store the current row in a variable so that it will be remembered on the next occurence. Then you'll have everything you need to calculate the value for the current occurence.
Of course the value will remain valid only if you don't make changes to the data.
Upvotes: 0