How to throw a error in asp.net if already exist
if i enter a email id in registration form ., then again i registration with another name but use the same email id ., i need to throw the error email id already exists in asp.net using c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Keyur Narkhi62 reputationPosted May 9, 2012, 9:02 PM EDT
For that you need to check in the database that email is exists or not.If email is exists then you can simply display a error message in the label that email is exists.
Or you can create the unique key on Email,which gives you an error on save for duplication and handle it in the catch block and display that error.
Hope this helps.
thanks
Krishna GaradRank #191 · 12.8K reputationPosted May 9, 2012, 10:33 PM EDT
Create Table TblUser
(
Name Varchar(100),
Email Varchar(50)Unique
etc....
)
When you are inserting values in the table first you need to check the email exists or not for the easiest you can use stored procedure like
Create Procedure Sp_RegisterUser
(
@name Varchar(200),
@email Varchar(50),
@message Varchar(200)out
)
As
Begin
if not exists(Select Email From TblUser Where Email=@email)
Begin
Insert Statement
Set @message='User Registered'
End
Else
Begin
Set @message='Email Already Exists'
End
End
Hope this may helps you
selvi subramanianRank #2,007 · 723 reputationPosted May 9, 2012, 9:15 PM EDT
Keyur Narkhi62 reputationPosted May 9, 2012, 9:20 PM EDT
Please follow this url
http://blog.sqlauthority.com/2007/02/05/sql-server-primary-key-constraints-and-unique-key-constraints/
http://www.w3schools.com/sql/sql_unique.asp
Hope this helps
thanks