Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have a datatable with 3 columns : debt , credit , remain, type

all cells now are filled like below :
debt/credit/remain/type
100   0     100    debt
200   0     300    debt
0     500   500    credit
0     200   200    credit
50    0     50     debt
150   0     150    debt
50    0     50     debt
5000  0     5000   debt


now i want to calculate remain column like below :
debt/credit/remain/type
100   0     100    debt
200   0     300    debt
0     500   200    credit
0     200   400    credit
50    0     350    credit
150   0     200    credit
50    0     150    credit
5000  0     4950   debt


thanks a lot
Posted
Updated 9-Dec-14 19:58pm
v3
Comments
Tomas Takac 9-Dec-14 8:29am    
The remaining amount doesn't seem to be correct. In foirst two rows it should be negative (-100, -300) and the last one should be -4850. BTW what did you try? This doesn't seem to be overly complicated.
[no name] 28-Dec-14 14:04pm    
thanks,this solved
Sinisa Hajnal 9-Dec-14 8:36am    
Also, which database? This is fairly easily done in database query, look it up.
[no name] 28-Dec-14 14:04pm    
thanks,this solved
Praveen Kumar Upadhyay 9-Dec-14 8:49am    
Can you please explain what is your calculation logic

1 solution

In your datatable, probably, the last row is number (datatable.Rows.Count-1)

So the 'cell' can be accessed at

var remain = datatable.Rows[datatable.Rows.Count-1]["remain"];

so you can now calculate the new value for the row you are adding.
 
Share this answer
 
Comments
[no name] 28-Dec-14 14:05pm    
thanks,this solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900