how to check if an email address already exists in the database in

In this article we can see how to find exiting email id from data base and it will display error message if it already exits
We created a method with name uniqueEmail.
Established a connection to the database.
Getting the data from the table  aspnet_Membership.
Using the ExecuteReader to read the values and checking the condition weather email id is already exists or not.

   public bool uniqueEmail()
                string iemail;
                string constr = ABCDataAccessLayer.ABCConnctionString; // connection string
                SqlConnection con = new SqlConnection(constr);
                string query = "select count(Email) as Email  from aspnet_Membership where Email= '" + txtEmailID.Text + "'";
                SqlCommand cmd = new SqlCommand(query, con);
                SqlDataReader dr;
                dr = cmd.ExecuteReader();
                while (dr.Read())
                    iemail = dr["Email"].ToString();
                    if (iemail != "0")
                        mailerror.Text = "Enter different email id";
                        return false;

                return true;

Keep if condition,if you want to check email in insert mode or update mode
if (uniqueEmail())
Insert Code logic //
Update Code Logic


chinnu jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment


  1. I started on SharePoint around and have gone through the same denials, acceptance, and now really loving the vast landscape of SharePoint. There is so much to learn, so many real world problems to solve, and so many fantastic ways to solve them.
    SharePoint Online Training