Duplicates Checking in Gridview

Posted by Krishnamanohar under ASP.NET on 10/18/2012 | Points: 10 | Views : 1399 | Status : [Member] | Replies : 1
Hi
I want to insert the data in gridview .but before inserting i want to check wether record exsists or not(Duplicate)
Pls Help me
Regards,
Krishna Manohar




Responses

Posted by: Vasanthmvp on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi KrishnaManohar,
You can write a Stored Procedure for this. Set a primary key in your table.
If i want to insert a record into a Student table (UserName,Course,DOJ) values (@UserName,@Course,@DOJ). If primaykey is my username
ALTER PROCEDURE Example_SP

@UserName varchar(MAX),
@Course varchar(MAX),
@DOJ DateTime
AS
BEGIN
If NOT Exists(Select * from TableName where UserName = @UserName)
begin
Insert INTO TableName(UserName,Course,DOJ) values(@UserName,@Course,@DOJ)
return 1;
end
else
begin
return -1;
end
END
GO

In the aspx page, catch the return value from the StoredProcedure into a return value parameter. Check if its value is 1 then we can show record inserted succesful msg or record already exists message.

Regards,

Awesome Coding !! :)

Krishnamanohar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response