That is simple enough to be written in just a few moments.
First you get the input from the user from the form or what so ever the medium. For example:
int userInput = Request.Form["some_input_name"];
And then get the data from the Database:
"SELECT * FROM Table Where username=" + username;
Now, you need to select the column otherwise you'll get an Exception. Try this:
int dbValue = "";
foreach (var row in variable_of_database) {
dbValue = row.amount;
}
Now, just subtract it.
int newValue = userInput - dbValue;
Then the same UPDATE
method.
There is a typo in your code:
"UPDATE Table SET amount='" + amount + "'WHERE username='" + userName + "'";
// ^^^ You sure?
Try updating it to the new variable name i.e. newValue
.