In the following code when I try to update amount in the table t_payment, I expect it to be set the value of Convert.ToInt32(request.amount+ previous_paid_amount); whereas previous_paid_amount is assumed to be 0 instead of getting updated. So I am unable to use the updated value of previous_paid_amount variable.
Any help would be highly appreciated. Thanks
double previous_paid_amount = 0;
try {
OracleCommand command2 = new OracleCommand();
command2.CommandText = "select amount from t_payment where penalty_order_id = (select id from t_penalty_order where protokol_no = :invoiceNumber)";
command2.Parameters.Add(new OracleParameter(@"invoiceNumber", OracleDbType.Varchar2, 255)).Value = request.invoiceNumber;
command2.Connection = connection;
command2.CommandType = System.Data.CommandType.Text;
using (OracleDataReader row2 = command.ExecuteReader()) {
while (row2.Read()) {
previous_paid_amount = Convert.ToInt32(row2.GetValue(0));
}
}
}
catch (Exception e) {
completePayment.code = 111;
completePayment.message = e.Message;
completePayment.transactionNumber = null;
}
// update the paid amount by adding the current amount
try {
OracleCommand command2 = new OracleCommand();
command2.CommandText = "Update t_payment set amount = :amount where penalty_order_id = (select id from t_penalty_order where protokol_no = :invoiceNumber)";
command2.Parameters.Add(new OracleParameter(@"amount", OracleDbType.Int32)).Value = Convert.ToInt32(request.amount+ previous_paid_amount);
command2.Parameters.Add(new OracleParameter(@"invoiceNumber", OracleDbType.Varchar2, 255)).Value = request.invoiceNumber;
command2.Connection = connection;
command2.CommandType = System.Data.CommandType.Text;
command2.ExecuteNonQuery();
}
catch (Exception e) {
completePayment.code = 111;
completePayment.message = e.Message;
completePayment.transactionNumber = null;
}