how to avoid to insert same data into database using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GAURAV MANUSMAR
    New Member
    • Feb 2014
    • 8

    how to avoid to insert same data into database using C#

    There is one database name as "email_book " and in that database there is one table named as "contact_book". ...name and mail_id are the two column which i had been created in that table.......now i want to add data into to my table using form in C# but on the counter part i just want to avoid inserting the repeated data into the table.......whe n user add same mail_id which is already present in the table then it must gives the message that "this mail_address is already present in database"...... ..so for that i need coading in C#

    .....please help its urgent
  • audrey45
    New Member
    • Feb 2014
    • 2

    #2
    if you are using EF
    DatabaseName db = new DatabaseName();

    var checkMail = db.TableName.Si ngle(d => d.mail_id == userMailId);
    if(checkMail == null){
    //Save your email
    }
    else{
    //Message: email is already exist
    }
    Last edited by audrey45; Feb 13 '14, 08:26 AM. Reason: wrong grammar

    Comment

    Working...