i have a table named brand
,fields are:
我有一个名为品牌的表,字段是:
-
BrandId
- BrandId
-
BrandName
. - 品牌。
Then I have a form for adding brand. If we add a brand name (eg:Acer).then if we add the same brand again there will check is already exist that name in the table. How can i check it in asp.net?
然后我有一个添加品牌的表格。如果我们添加一个品牌名称(例如:Acer)。然后,如果我们再次添加相同的品牌,那么将检查表格中是否存在该名称。我如何在asp.net中查看它?
2 个解决方案
#1
2
If
you want to insert new record than use
如果要插入新记录而不是使用
if exists(select brandName from [brand] where brandName <> @pbrandName)
-- insert statement
Else if
you want to update the existing record than you can use.. (by using existing record id)
否则,如果你想更新现有的记录,你可以使用..(通过使用现有的记录ID)
if exists(select brandName from [brand] where BrandId <> @pBrandId and brandName <> @pbrandName)
-- update statement
#2
0
If you are using Sql server
如果您使用的是Sql server
declare @Exist INT=0
Select @Exist= COUNT(BrandName)
From TableName
Where BrandId= IdValue
Group By(BrandName)
IF(@Exist=0)
BEGIN
--Insert
END
#1
2
If
you want to insert new record than use
如果要插入新记录而不是使用
if exists(select brandName from [brand] where brandName <> @pbrandName)
-- insert statement
Else if
you want to update the existing record than you can use.. (by using existing record id)
否则,如果你想更新现有的记录,你可以使用..(通过使用现有的记录ID)
if exists(select brandName from [brand] where BrandId <> @pBrandId and brandName <> @pbrandName)
-- update statement
#2
0
If you are using Sql server
如果您使用的是Sql server
declare @Exist INT=0
Select @Exist= COUNT(BrandName)
From TableName
Where BrandId= IdValue
Group By(BrandName)
IF(@Exist=0)
BEGIN
--Insert
END