<p>We have a Cash flow report which is basically in this structure:</p>

<pre><code>Date |Credit|Debit|balance|
09/29| 20   | 10  | 10    |
09/30| 0    | 10  | 0     |
</code></pre>

<p>The main problem is the balance, and as we are using a DataSet for the Data, it's kinda hard to calculate the balance on the DataSet, because we always need the balance from the previous day.</p>

<p>Also this data comes from several tables and it's been hard to maintain this procedure, because the database metadata is changing frequently.</p>

<p>Anyone could give me some possible different solutions? for the problem?</p>

<p>This report is being displayed on a DataGrid.</p>

On the code side of things, you've got two relatively easy options, but they both involve iterating through the dataset.
option 1: For loop prior to databinding.
For each row in the datatable, add/subtract the credit/debits to the previous row's balance and assign it to the appropriate cell of your datatable.
Option 2: calculate during databinding.
First you'd have a global variable that you could hold your value in. Set it to zero right before the databind. For each item or altitem, add/subtract the credit/debits to the global variable and assign it to the appropriate cell of your datagrid.