Click here to Skip to main content
15,918,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,


How to know the email address is available in the database while doing registration


Thanks
Posted
Updated 3-Sep-11 9:44am
v2

Run a query selecting the rows or COUNT where the email is the same as the input email.

E.g.
C#
SqlCommand command = new SqlCommand("SELECT COUNT(*) FROM users u WHERE u.email = :EMAIL", myConnection);
command.Parameters.Add(":EMAIL", SqlDbType.VarChar).Value = inputEmail;
int count = (int) command.ExecuteScalar();
if(count != 0)
{
    // The email is already used
}
 
Share this answer
 
v3
During the registration, you can validate the database and check if the email id is exist of not. You can also take help of AJAX or JQuery to do it behind the scene.
 
Share this answer
 
If I understood your question correctly, it's a quite broad question. It would include at least the following steps:

  • create a table for existing accounts containing the email addresses
  • when a new registration is going on:

    • create a connection
    • create a command
    • define a select statement checking for the email existence. Something like:
    • SQL
      select count(*) from account where email = @email

    • check if the result is 0. If it is, the email address is already registered
    • complete the registration
    • add the new email address to new account row (remember possible case-sensitivity in the database)
    • commit the changes

  • let the user know if the operation was successful


Some of the classes needed for this (for Sql Server if that is used):
 
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