验证以在插入之前检查重复记录 [英] validation to check duplicate records before inserting

查看:59
本文介绍了验证以在插入之前检查重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证来限制数据库中重复数据的条目。我使用asp.net,c#和sql server作为我的开发环境。

我在一个名为''CGRT'的数据库中总共有四个表,表名是项目,员工,每年,每月。请给我一个解决方案,以便我可以限制重复数据的条目,如果它在客户端有一个错误消息,我会更喜欢。

i need a validation to restrict the entries of duplicate data in my database. i am using asp.net, c# and sql server as my development environment.
i have in total four tables in a database called ''CGRT'' and table names being project,staff,yearly,monthly . please give me a solution so that i can restrict the entries of duplicate data i would prefer if its at client end with a error msg.

推荐答案

我不是为你编写代码!



如果资源使用不是问题,表格中的行数为100行或更少,我会这样做的方式是将相关表格加载到 DataSet [ ^ 并搜索第一列中的所有行(如果第一列中没有记录ID列),如果第一列适合使用 String.Compare()比较行上的每个相关性字段并且应该全部匹配,然后返回错误消息或任何你想要的。



现在我使用C#进行桌面操作,所以我不需要要担心资源,但如果这是在一个网站calli另一个网站SQL服务器,它不是一个好的解决方案。



希望这对你有帮助!



-frank



PS:如果我完全错过了这个问题,请随时对此发表评论
I''m not coding it for you!

The way I would have done it, if resource use was not an issue, and it was 100 or less rows in the tables, was to load the relevant table(s) into a DataSet[^] and search through all rows in the first column (not the record ID column if it has one), if the first fits compare each relavant field on the row using String.Compare() and should all match, then return error message or whatever you want.

Now I use C# for desktop so I don''t need to worry to much about resources, but if this is on a website calling another websites SQL server, it''s not a good fix.

hope this was helpful!

-frank

PS: feel free to comment on this if I''m missing the point of the question entirely


更好和最优化的解决方案是编写一个查询或存储过程,如果count不等于零,则返回现有值的计数意味着您已经在表中已经有此记录跳过进一步插入。



术语重复条目仅由您定义,因此您必须使用参数修改查询,示例查询如下所示。



例如:从学生中选择count(staffName),其中staffName =''Bingo''

此查询将返回与staffName Bingo匹配的项目数。如果Bingo已经存在,它将返回0.否则出现次数
The better and most optimized solution is to write a query or stored procedure which returns the count of the existing values if count is not equal to zero means you already have this record in your table skip further insertion.

The term ''Duplicate Entries'' only be defined you so you have to modify the query with your parameter a sample query look like this.

eg: select count(staffName) from student where staffName =''Bingo''
this query will return number of items that matches staffName Bingo. If Bingo already exists it will return 0. else the number of occurrence


hi,



您可以使用 EXISTS 为您的解决方案。



You can use EXISTS for your solution.
SELECT DepartmentID, Name 
FROM HumanResources.Department 
WHERE EXISTS (SELECT NULL)
ORDER BY Name ASC ;





请参阅此链接以获得更好的结果。防止重复记录录入



谢谢



Refer this link for better result.Preventdiuplicate record entry

Thanks


这篇关于验证以在插入之前检查重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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