Solved

how to avoid Duplicate when you insert record

Posted on 2011-03-19
4
398 Views
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
0
Comment
Question by:Sha1395
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
ramkihardy earned 250 total points
Comment Utility
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...
Regards
Ramki
0
 
LVL 3

Assisted Solution

by:exceter
exceter earned 250 total points
Comment Utility
Also you can create a temporary table and insert there initially with INSERT INTO .... SELECT DISTINCT EmailID...
0
 

Author Comment

by:Sha1395
Comment Utility
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
0
 
LVL 2

Expert Comment

by:ramkihardy
Comment Utility
Please mark it as accepted solution...
Thanks & regards
Ramki
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now