撤消Access数据库中的更新 [英] Undo an update in Access database

查看:137
本文介绍了撤消Access数据库中的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!我的项目是分期付款程序(VB.NET 2008),我使用MS Access作为数据库.当用户注册一个新客户时,它将根据在注册窗口中输入的术语数自动在表中生成每个术语的金额.这样的代码可以正常工作.
另一种形式(Premiums形式)要求用户输入客户支付的保费,保存按钮的代码如下所示:

Hi guys! My project is an installment payment program (VB.NET 2008) and I use MS Access as database. When the user enrolls a new customer, it will automatically generate amounts per term in the table based on how many terms is entered in the enrollment window. The code of this works fine.
Another form (Premiums Form) asks the user to input the premium paid by the customer, and the code of the save button looks something like this:

Private Sub btnPremSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPremSave.Click

  sqlQrySave = "UPDATE MyTable SET custnam = ''" & cboCustNam.Text & "''," _
  & "premno = ''" & txtPremNo.Text & "'', premamt = & ''" & txtPremAmt.Text & "''," _
  & "WHERE contno = " & txtContNo.Text & ""

  cmdSave = New OleDbCommand(sqlQrySave, connSave)
  cmdSave.ExecuteNonQuery()

End Sub



在保费表格中,如果有错误的更新,我有一个UNDO按钮来还原表中的更改.客户可能会支付比所支付的价格更高的价格,因此在单击保存"按钮之前保存了原始值的"premamt"列中,我应该能够返回原始值,并丢弃最近保存的值.有没有简单的方法可以做到这一点?

预先感谢您的帮助! :-D



In Premiums Form I have an UNDO button to revert the changes in the table, in case of erroneous updates. The customer might pay higher than what is dealt, so in the "premamt" column where there were original values saved before clicking this SAVE button, I should be able the return the original values, and discard the recently saved. Is there an easy way to do this?

Thank you in advance for the help! :-D

推荐答案

我认为这是为了做作业,现实世界中没有人会使用此代码?无论哪种方式,学习编写不会对注入攻击开放的安全代码仍然对您有益.

您的数据库没有内置撤消功能.您必须摆脱按钮或跟踪更改,以便运行撤消更改所需的SQL.请记住,没有保证在查询中更改的对象具有相同的开始值.
I assume this is for homework and that no-one in the real world will ever use this code ? It would still be good for you to learn to write safe code that is not open to injection attacks, either way.

Your database does not have undo built in. You have to either get rid of the button, or track your changes so you can run the SQL needed to undo the change. Remember that there is no guarentee that the objects changed in your query had the same value to start with.


一种方法是将默认值存储在另一个表中,并在如果用户恢复了这些值,请从表中获取它们,然后显示它们.
One way to do this would be store the default values in a another table, and in case the users revert back to the these values, fetch them from the table and then display them.


好吧,正如克里斯蒂安所说,您需要某种方式来跟踪更改.一种方法是将付款保存在单独的表中,该表通常称为PaymentHistory或类似名称.这样,您可以进行与付款一样多的撤消"操作.

同样,正如克里斯蒂安所说,您应该尝试使用参数化查询以避免注入攻击.
Well, as Christian has said, you need some way to track changes. One way to do this is to have payments in a separate table, often called PaymentHistory or something similar. that way you can have as many ''undos'' as there are payments.

Also as Christian stated you should try to use Parameterized Queries to avoid injection attacks.


这篇关于撤消Access数据库中的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆