how to avoid Duplicate when you insert record

Posted on 2011-03-19
Medium Priority
Last Modified: 2012-05-11
Am trying to insert a record pulled out from Active Directory but i can see so many duplicates,how can i avoid when i insert those records.

for eg

will.smith@gmail.com repeat 5 times,i just don't want to insert a duplicate record based on mail id.

any one pleas enlighten me.

Thanks in Advance
Question by:Sha1395
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

ramkihardy earned 1000 total points
ID: 35171208
simple you can set the maildid column unique in the table which you want to enter.......
when you try to insert a duplicate email id..it throws an error...catch that error it consist of errorid for duplicate record insertion...you can check if duplicate record inserted in catch...like
if(errid=="error id for duplicate record insertion")
Messagebox.show("Record alreadyb exist");
2.Otherwise you have to select the distinct record so that it wont contain any duplication...

Assisted Solution

exceter earned 1000 total points
ID: 35171233
Also you can create a temporary table and insert there initially with INSERT INTO .... SELECT DISTINCT EmailID...

Author Comment

ID: 35171548
Thanks Ramki and Exceter.

As you people mentioned i make Email Id is a primary key and use TRY  Catch in my code.its done.

Thanks again for all your help

Expert Comment

ID: 35171602
Please mark it as accepted solution...
Thanks & regards

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question