如何使用c#防止Access数据库中的重复条目? [英] How to prevent duplicate entries in an Access database using c#?
问题描述
如果该字段不是您的主键字段,则可以在包含"ankush"的字段上设置索引,并使该索引唯一
[Index=Yes(no duplicates)]
然后,Jet DB Engine将不允许插入,并显示默认消息.
我正在使用Access的旧版本,因此您的里程可能会有所不同,但是要显示自定义错误消息,您必须首先对表中的值进行查询,如下所示:
SELECT COUNT(MyField)as violated FROM MyTable WHERE MyField = 'input value here'
如果违反了代码,则在代码中分支> 0以显示您的消息框.
i have a table of MS Access which contains one column and many rows. The value of a textbox saved to this table. I want to prevent duplicate entries from being submitted. For example, if I type "ankush" in the textbox and this entry already exists in table, then I want to display a msgbox saying that this already exists in the table. using c#
If the field is not your primary key field you can set an index on the field that contains 'ankush' and make that index unique
[Index=Yes(no duplicates)]
then the Jet DB Engine will not allow the insert and will show a default message.
I am working with an older version of Access, so your mileage may vary, but to show a custom error message you would have to first do a query for the value in the table like this:
SELECT COUNT(MyField)as violated FROM MyTable WHERE MyField = 'input value here'
Then branch in your code if violated > 0 to show your message box.
这篇关于如何使用c#防止Access数据库中的重复条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!