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