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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Krishna GaradPosted May 10, 2012, 2:33 AM
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
Keyur NarkhiPosted May 10, 2012, 1:02 AM
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
Keyur NarkhiPosted May 10, 2012, 1:20 AM
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
selvi subramanianPosted May 10, 2012, 1:15 AM