我已禁止在 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.
我只想显示“抱歉 - 记录已存在”,而不是这条冗长的消息。
这可能吗?
最佳答案
有两种方法可以做到这一点:
捕获错误。我认为经典 ASP 需要
on errorresume next
,然后您需要检查错误消息。您甚至可能必须匹配该字符串,因为我认为不同错误的错误代码是相同的。在
插入
之前从数据库中执行select
以检查该值是否已存在
无论哪种方式,您都可以显示您自己的消息。进一步自定义消息可能会更加用户友好(“抱歉 - 物种‘Gruffalo’已经存在”)。
关于ms-access - 如果在 Access 数据库中插入重复数据,则显示人为错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167726/