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

Advertisement
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);
                con.Open();
                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 //
or
Update Code Logic
}

Output:
Advertisements
SHARE

Unknown

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

13 comments:

  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

    ReplyDelete
  2. Nice knowledge gaining article. This post is really the best on this valuable topic. UC mini app

    ReplyDelete
  3. i want this code in mvc without entity framework

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Really I Appreciate The Effort You Made To Share The Knowledge. This Is Really A Great Stuff For Sharing. Keep It Up . Thanks For Sharing.

    Cloud Training
    Cloud Training in Chennai

    ReplyDelete
  6. Great post, thank you for sharing. I want to add one more tool to your collection: improver.io. It's my favorite Chrome extension for contact finding.find email from linkedin

    ReplyDelete
  7. In fact, the system is considered to be so important that it's now considered a necessary part of any modern database systems.dbdesigner.net

    ReplyDelete
  8. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... correo hotmail

    ReplyDelete
  9. Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for. I would like to recommend you that please keep sharing such type of info.If possible, Thanks. sign in to Hotmail

    ReplyDelete
  10. i never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. www.hotmail.com

    ReplyDelete