By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,899 Members | 1,230 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,899 IT Pros & Developers. It's quick & easy.

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

P: 8
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.......when 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
Feb 13 '14 #1
Share this Question
Share on Google+
1 Reply


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

var checkMail = db.TableName.Single(d => d.mail_id == userMailId);
if(checkMail == null){
//Save your email
}
else{
//Message: email is already exist
}
Feb 13 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.