如何限制重复值无法保存 [英] How to Restrict That Duplicate Value would not Saved

查看:77
本文介绍了如何限制重复值无法保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个显示类别(SC,ST,OBC等)的类别表.我正在从文本框中保存这些值.例如,如果有人想再次添加存在于数据库中的SC,则单击保存"按钮,消息显示类别在DB中可用,您无法再次保存.
怎么可能.


感谢您的问候,
Amit Mehan

Hello All,

I have a Category Table which Shows Categories(SC,ST,OBC etc).I am saving these values from Textbox.For example if some one wants to add SC again which is present in Database,then on click save button message shown that this category is available in DB and you cant save it again.
How it is possible.


Thanks with Regards,
Amit Mehan

推荐答案

两种方式之一:

1)您将必须检查值是否存在,并报告问题.
2)可以在数据库中将SC字段设置为唯一-尝试再次添加它会引发错误,请陷阱并报告.

这取决于您和数据库设计的方向.
One of two ways:

1) You will have to check if the value exists, and report the problem.
2) The SC field could be set as unique in the database - attempts to add it again would then throw an error, which you trap and report.

It''s up to you, and your database design, which route you take.


您可以编写自己的vaildator逻辑来执行此操作-请参见
You could write yout own vaildator logic to do this - see here[^].


存在两种方式
1.将主键放在数据库的类别"列中,这样重复的插入将引发违反主键的错误.
2.从数据库中获取所有已保存的类别并将其存储在arraylist中,然后在将类别检查的存在性保存在arraylist中
two ways exist
1. put primary key on Category column in database so duplicate insertaion will throw error of primary key violation.
2. fetch all saved category from database and stored it in arraylist and then while saving category check existance in arraylist


这篇关于如何限制重复值无法保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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