Click here to Skip to main content
16,007,760 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i made a web application and when i insert a data from text box to table i want to check data is already exist or not .if data is already exist then i want a message "data is already exists" what type of query i should wrote ?

or how to use not exists query ?

i am using sql server.

Thanks in advance
Posted
Comments
Varun Sareen 21-Feb-12 2:17am    
have you tried something yet?
mayankshrivastava 21-Feb-12 2:19am    
ya i tried not exists clause.

1 solution

Create proc similar to the following & check the return value and show the message accordingly..
SQL
Create Procedure Proc_Name
(
    @EMailAdress varchar(50) = null,
}
AS

IF EXISTS (SELECT UserID  FROM E-MAIL WHERE EMailAdress = @EMailAdress)
BEGIN
    return 0
END
ELSE
BEGIN
    INSERT INTO E-MAIL (UserID,EMailAdress,Description) VALUES (UserID,@EMailAdress,@Description)
    return 1
END


In the code, check for the return value something like...
C#
int returnValue =  (int) comm.ExecuteScalar();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900