ms-access - 如果在 Access 数据库中插入重复数据,则显示人为错误

标签 ms-access asp-classic

我已禁止在 Access 数据库中重复记录,因此没有人会一次又一次地插入相同的数据。它工作正常,但错误消息对用户没有帮助,我想以更人性化的方式显示该错误。

Microsoft JET Database Engine (0x80004005)

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

我只想显示“抱歉 - 记录已存在”,而不是这条冗长的消息。

这可能吗?

最佳答案

有两种方法可以做到这一点:

  1. 捕获错误。我认为经典 ASP 需要on errorresume next,然后您需要检查错误消息。您甚至可能必须匹配该字符串,因为我认为不同错误的错误代码是相同的。

  2. 插入之前从数据库中执行select以检查该值是否已存在

无论哪种方式,您都可以显示您自己的消息。进一步自定义消息可能会更加用户友好(“抱歉 - 物种‘Gruffalo’已经存在”)。

关于ms-access - 如果在 Access 数据库中插入重复数据,则显示人为错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167726/

相关文章:

vb.net - 将 Blob 图像导入 ms Access 报表时出现异常

vb.net - OleDbAdapter错误,在封闭 block 中隐藏变量错误

mysql - 使用 If 语句比较从 MySQL 中提取的数字

php - 通过 MSXML2.ServerXMLHTTP 发送 POST 数据时,是否需要输入名称?

javascript - 使用动态字段名称进行表单验证

string - 将 UTF-8 字符串转换为 ISO-8859-1

ms-access - 网站使用的MS Access DB

ms-access - 使用 With...End 在使用 DAO 的 Ms Access 中打开记录集时

php - 更新时 MS Access 错误 "Operation must use an updatable query"

html - 如何在经典的 ASP Web 应用程序之上集成 WebSockets?