I want to prevent the insertion of duplicate records,if the record is already exists then I want to send a message the record already exists.
please find the below file,It contains my database image.
I want to insert the data through regid,diffrent users can enter the same data but when the same user trying to enter same record 2 time then I should prevent.
In the below picture I rounded with blue(Regid:45),the user can able to enter like that but when the user is trying to enter same details with same regid(45) then I should restrict.Can any one tell me how to write the code for this
Loading
Usha RajPosted Apr 13, 2015, 6:09 AM
Syed ShanuPosted Apr 13, 2015, 5:36 AM
Here is sample Stored procedure
Create PROCEDURE [dbo].[USP_YOURINSERT]
(
@JOBTitle VARCHAR(30) = '',
@RegID VARCHAR(20) = '',
@RequirementID VARCHAR(50) = '',
@ReuiredExp VARCHAR(50) = '',
@JobLocation VARCHAR(50) = '',
@rowNum INT =0
)
AS
BEGIN
IF NOT EXISTS (SELECT * FROM YOURTABLENAME WHERE JOBTitle=@JOBTitle and RegID=@RegID)
BEGIN
INSERT INTO [YOURTABLENAME]
(JOBTitle,RegID,RequirementID,ReuiredExp,JobLocation,rowNum)
VALUES
(@JOBTitle,@RegID,@RequirementID,@ReuiredExp,@JobLocation,@rowNum)
GOTO S1_RTN
Select 'inserted'
END
ELSE
BEGIN
Select 'JobTitle Exists'
END
END
You can check my Article with similar Example.
http://www.c-sharpcorner.com/UploadFile/asmabegam/insert-select-update-delete-in-Asp-Net-with-simple-login/
Khargesh RajputPosted Apr 13, 2015, 5:34 AM
select id from tbl where title=@title
if it returns record>0
then message 'record allready exists"
else
"insert record'