select count(1) from [table] where condition 返回值大于0 说明存在
select count(*) from table where A=textbox的值 如果数据库有这条数据 返回值大于0 判断一下 然后 提示messagebox.show("已存在");
select count(*)..判断是否存在 或not exists(select 1 from table where id=@id) insert into...
if not exists(select 1 from table where id=@id) insert into...
在数据库里写一个存储过程,类似楼上写的那样 CREATE PROCEDURE sp_SaveData ( @Desc nvarchar(260), @Result int OUTPUT ) ASbegin set nocount on -- Result return Error Codes: -- 0 - Successful. -- 1 - alreay exist in database. if not exists (select * from 【表】 where 【column名】 = @Desc ) begin insert into 【表】 (【column名】) values (@Desc ) set @Result = 0 return end else begin set @Result = 1 return end然后在程序中调用这个存储过程并根据返回值 如果返回值result为1表示已经有记录
string sqlMold_pn = "select 1 from mold_base where mold_pn='" + tnMold_Pn.Text + "'"; 判断是否大於1
返回值大于0 说明存在
如果数据库有这条数据 返回值大于0 判断一下 然后 提示messagebox.show("已存在");
或not
exists(select 1 from table where id=@id) insert into...
CREATE PROCEDURE sp_SaveData (
@Desc nvarchar(260),
@Result int OUTPUT
) ASbegin
set nocount on -- Result return Error Codes:
-- 0 - Successful.
-- 1 - alreay exist in database. if not exists (select * from 【表】 where 【column名】 = @Desc )
begin
insert into 【表】 (【column名】) values (@Desc )
set @Result = 0
return
end
else
begin
set @Result = 1
return
end然后在程序中调用这个存储过程并根据返回值 如果返回值result为1表示已经有记录
判断是否大於1