在插入新记录之前检查项是否存在 [英] check if an item exists before inserting a new record

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

问题描述

如何在从数据库中删除和插入项目之前检查记录是否存在

并显示一个c#代码,用于检查是否可以插入或删除项目。

谢谢你能帮忙

how do I check if a record exist before deleting and inserting an item from the database
and also show a c# code that check if the items can be inserted or deleted.
thanks if you can help

推荐答案

查看下面提到的链接并选择适合你的东西(SP和TSQL都在那里)< br $> b $ b

如何使用c#代码检查sql表中是否存在特定项目





c#检查记录是否存在于SQL



我希望这会对你有所帮助。
Check below mentioned links and select what exactly suitable for you (SP and TSQL both are there)

How to check if a particular item exists in a sql table using c# code


c# checking if record exists in SQL

I hope this will help to you.


当我们在一个表上执行DELETE命令时, WHERE子句将在继续之前检查是否存在记录。对于INSERT命令,表的主键将防止任何重复记录。所以,确实没有必要进行存在检查。



在C#中,你可以使用ExecuteNonQuery来执行插入和删除操作,返回值是行数受命令影响。该返回值将告诉我们操作是否成功。
When we perform DELETE command on a table, the WHERE clause will check for the existence of a record before proceeding. As for INSERT command, the primary key of the table will prevent any duplication of record. So, there is really no need to do existence check.

In C#, you can use ExecuteNonQuery to perform insert and delete operations, the return value is the number of rows affected by the command. This return value will tell us if the operation is successful or not.


检查数据库中是否存在表或字段 [ ^ ]



check-if-record -in-a-table-in-a-database-through-executenonquery [ ^ ]


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

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