Saturday, 28 September 2013

Get the value of certain column in datagridview before and after changes

Get the value of certain column in datagridview before and after changes

i have a problem where i can't solve it by myself. And before i start, it
is important to let you guys know that
This problem i wrote from the beginning to the end, i want to make you
guys understand properly what my problem is, for those who are lazy to
read this, please forgive me, i am not attach any code in here, only just
logic
Probably people in this forum could help me. But, i already got a solution
to my problem (but only the logic, i can't prove it by code and don't know
where to start)
Well, here is my case:
I got a Quantity column in DataGridView, and i got a feature where user
could edit the Quantity column in DataGridView and automatically updating
the Quantity value in the Database.
For Example (still at the case):
I have 1000 on Quantity in the Database, and i enter the value of 50 in
the Quantity column in system and after that i add to the DataGridView by
clicking a "OK" button, once clicked, the Quantity in the Database should
update it Quantity become 950, from 1000. Because i use a formula
valueOfQuantityInDatabase - valueOfQuantityInSystem, it update properly
and successful
Here is my problem goes:
Let's say i got a DataGridView with Quantity column and the value of it is
50 (This make a Quantity value in Database become 950) and let's say
customer want to add his Quantity from 50 to 150, so i change the value of
Quantity in DataGridView to 150 from 50, and when i click "OK" button, the
Database should update based on the formula valueOfQuantityInDatabase -
valueOfQuantityInSystem, and the Quantity in Database should have 850 in
Quantity value (Because 1000 - 150), but it is not as i expected, the
Quantity value in database is 800 (Because first time i add is 50, so the
Quantity in database is 950, next i add another 150 and the Quantity in
database is 800), so it is like first entered value + second entered
value.
Here is what i want:
Whenever user edit the Quantity in DataGridView, it should goes to this
formula valueOfQuantityInDatabase - valueOfQuantityInSystem ------ (So,
whenever user change the Quantity value in DataGridView, let's say it
change to 150 from 50, the Quantity in Database should recognized it and
minus with current value of Quantity in DataGridView (150), not the older
one (50)
Here is my solution that i came with:
Get the first value of Quantity in Database before it was changed (1000)
Get how many value of Quantity that has been added from user by formula
Quantity in DataGridView after changes - Quantity in DataGridView before
changes and plus it with the formula Quantity in DataGridView after
changes - Quantity in DataGridView before changes
But i don't know how to get the solution 1 nor 2. Could anyone help me?
Thank you very much! Your answer i appreciate so much!

No comments:

Post a Comment