防止用户输入重复值 [英] Preventing Duplicate values entered by user

查看:24
本文介绍了防止用户输入重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止用户使用 SQL 查询插入重复值数据类型为 VarChar(50)

How do I prevent users from a inserting a duplicate value using SQL Query datatype is VarChar(50)

例如name 字段已经定义为Josh",我不希望它能够添加另一个Josh"

e.g. the name field has already been defined as "Josh", I don't want it to be able to add another "Josh"

推荐答案

在数据库字段中设置唯一键约束.但这会抛出一个 SQLException,您需要捕获该异常才能向用户显示正确的错误消息.

Set unique key constraint in the database field. But this would throw an SQLException which you will need to catch to display a proper error message to the user.

有关唯一键的更多信息... http://msdn.microsoft.com/en-us/library/ms191166.aspx

More on Unique keys... http://msdn.microsoft.com/en-us/library/ms191166.aspx

这篇关于防止用户输入重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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