Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want find the entering email address is existed or not
my script
HTML
<script>
    function ABC() {
        var email = $('#Email').val();
        //alert(email);
        $.ajax({
            url: '/person/CheckEmail',
            type: 'GET',
            data: 'email='+ email,//{email:email},         /*'id="' + email+'",*/
            cache: false,
            success: function (html) {
                alert(html);
            }
        });
    }
</script>

personContoller
C#
public string CheckEmail(string email)
      {
         //how to write code for find existing email id
      }


database name person
table name people
table fields are..
name
email
profession
age

please help me

Regards
AR
Posted
Updated 7-Mar-14 22:10pm
v2

1 solution

For demo I have created similar example. First I created Person class as model and Dummy database:
 public class Person
 {
     public string Name { get; set; }
     [DataType(DataType.EmailAddress)]
     public string Email { get; set; }
     public string Profession { get; set; }
     public int Age { get; set; }

 }

public class DummyDatabase
 {
     public List<Person> GetAllPersons()
     {
         return new List<Person> {
             new Person () {  Name = "Arti", Email = "arti@abc.com",
                              Profession = "Engineer", Age = 25},
             new Person () {  Name = "Deepak", Email = "deepak@gmail.com",
                              Profession = "Engineer", Age = 25}

         };
     }
 }


Now In controller I am writing the method like:
C#
public string CheckEmail(string email)
       {
           DummyDatabase db = new DummyDatabase();
           var allPerson = db.GetAllPersons();

           var result = (from p in allPerson 
                            where p.Email == email select p).ToList();

           if (result.Count > 0)
           {
               return "Exist";
           }
           else
           {
               return "Does not exist";
           }
       }


Hope it will help you to get an idea to implement in your code.


Use ADO.NET or Entity Framework to connect to database.
For Entity Framework go to:
Simple Sample with Entity Framework [^]
and
http://msdn.microsoft.com/en-us/data/ee712907.aspx

For ADO.NET please visit: Using ADO.NET for beginners[^]
 
Share this answer
 
v3
Comments
An@nd Rajan10 8-Mar-14 5:39am    
thank you...
i want get data from database but you get data from a function thats have a list
how get data from database

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