如何避免在c#.net中的添加查询中重复 [英] how to avoid duplication in add query in c#.net

查看:54
本文介绍了如何避免在c#.net中的添加查询中重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有问题.
我想避免在database.重复中,所以每当我想在表单中添加特定数据并按添加按钮时,它也将获得重复值,这意味着它还会添加已经存在的字段..

是的,我不想通过主键使用它,因为如果我编写重复的值,则Visual Studio不会响应..

I have a problem in my project.
i want to avoid duplication in my database.so whenever i want to add particular data in form and press add button it also takes duplicate value means it also add that field which is already present..

and yeah i dont want to use it through primary key because if i write a duplicate value then visual studio is not responding..

推荐答案

您的问题非常模糊.如果您的主键是复合键,那么如果这些键必须是唯一的,则应该使用它.或在数据库表上创建唯一约束.或者只是在插入之前检查值.

即使您花很少的时间思考,这也是一个非常容易解决的问题.
Your question is very vague. If you have a primary key that is a composite then you should be using it if those are the fields that must be unique. Or create unique constraints on the database table. Or simply check the values before doing the insert.

This is a very easy problem to solve even if you spend very little time thinking about it.


在插入数据库之前,请先检查一下它的简单
before inserting into the database check once its simple


使用此查询检查
Check With this query
select count(columnname) from tableName
where columnname=@Value


并检查代码是否返回0,然后允许返回大于0的其他代码
不允许并确保它只返回1或0
因为您不需要重复.

快乐编码


and check in code if this returns 0 then u allow else if it return greater than 0
dont allow and make sure it should return only 1 or 0
as you need no duplication.

happy coding


这篇关于如何避免在c#.net中的添加查询中重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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