Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查表中已存在的tha数据_C#_Asp.net - Fatal编程技术网

C# 检查表中已存在的tha数据

C# 检查表中已存在的tha数据,c#,asp.net,C#,Asp.net,我有一个名为品牌的表,字段为: BrandId BrandName 然后我有一个添加品牌的表格。如果我们添加一个品牌名称(例如:宏碁)。然后,如果我们再次添加相同的品牌,将检查该名称是否已存在于表中。如何在asp.net中检查它?如果您使用的是Sql server declare @Exist INT=0 Select @Exist= COUNT(BrandName) From TableName Where BrandId= IdValue Group By

我有一个名为品牌的表,字段为:

  • BrandId
  • BrandName

然后我有一个添加品牌的表格。如果我们添加一个品牌名称(例如:宏碁)。然后,如果我们再次添加相同的品牌,将检查该名称是否已存在于表中。如何在asp.net中检查它?

如果您使用的是Sql server

declare @Exist INT=0
    Select @Exist= COUNT(BrandName)
    From TableName
    Where BrandId= IdValue
    Group By(BrandName)  
 IF(@Exist=0)
   BEGIN
     --Insert
   END

如果要插入新记录而不是使用

if exists(select brandName from [brand] where brandName <> @pbrandName) 
-- insert statement

表名是指数据库表吗?如果您使用的是哪个
db
?如何连接到SQL server?查询或实体框架?哪个数据库?而且,如果品牌名应该是唯一的,那么这个要求应该在数据库表上设置唯一索引为true,无论您使用的是什么数据库
if exists(select brandName from [brand] where BrandId <> @pBrandId and brandName <> @pbrandName) 
-- update statement