【发布时间】:2019-06-13 10:56:22
【问题描述】:
在下面的代码中,当我尝试更新表 t_payment 中的金额时,我希望它被设置为 Convert.ToInt32(request.amount+ previous_paid_amount); 的值,而 previous_paid_amount 被假定为 0 而不是更新。所以我无法使用previous_paid_amount 变量的更新值。
任何帮助将不胜感激。 谢谢
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;
}
【问题讨论】:
-
有些奇怪。 previous_paid_amount 被声明为 double,但分配为 int "previous_paid_amount = Convert.ToInt32(row2.GetValue(0))" 然后随着 request.amount (typeof?) 递增,总和重新转换为 int