?
Solved

VB.Net - Comparison to figure out if there are duplicates

Posted on 2007-11-29
6
Medium Priority
?
154 Views
Last Modified: 2011-10-03
I have the following scenario.  I have a SQL Server table that holds PERSON data such as name, address, phone number etc..  The Email_ID is the Primary Key.  I have 6 kinds of Persons:

1.  Requestor           -   bobscott@yahoo.com  - strRQEmailID
2.  Project Leader    -   bobscott@yahoo.com - strPLEmailID
3.  Primary Contact  -   lindamathews@yahoo.com - strPMEmailID
4.  Admin Contact   -    ronsloan@yahoo.com - strADEmailID
5.  Technical Contact  -  shirleywhite@yahoo.com - strTCEmailID
6.  24HrSupport Contact - ronsloan@yahoo.com - strTWEmailID

The persons in 1 and 2 (don't have to be) but they can be the same person.
The persons in 3,4,5,6 can be the same person also.

I have 6 separate strings that hold the email-ids of each.    What I need to do is compare each email-id to the other and determine which ones are unique and which ones are duplicates.  Then I need to discard the duplicates and INSERT only the ones that are unique.  As I mentioned earlier, the EmailID is the Primary key.

Can someone please help with the logic of the code (in VB.Net).    I don't have a code snippet to attach because I don't know where to begin.
0
Comment
Question by:msyed1
[X]
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
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
jcoehoorn earned 2000 total points
ID: 20377158
It's typically a good idea to use the existing data structures provided for you.  As it happens, most of the collections already provide a way to see if an item exists.  I'll show you the list, since it's the simplest:

    Dim keys As New System.Collections.Generic.List(Of String)
    keys.Add(strRQEmailID)
   
    If Not keys.Contains(strPLEmailID) Then keys.Add(strPLEmailID)
    If Not keys.Contains(strPMEmailID) Then keys.Add(strPMEmailID)
    If Not keys.Contains(strADEmailID) Then keys.Add(strADEmailID)
    If Not keys.Contains(strTCEmailID) Then keys.Add(strTCEmailID)
    If Not keys.Contains(strTWEmailID) Then keys.Add(strTWEmailID)

    Dim conn As New SqlClient.SqlConnection("your connection string here")
    Dim cmd As New SqlClient.SqlCommand("INSERT INTO PERSON (Email_ID) VALUES (@Email)", conn)
    Dim param As SqlClient.SqlParameter = cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50)
   
    conn.Open()
    For Each key As String In Keys
        param.Value = key
        cmd.ExecuteNonQuery()
    Next key
    conn.Close()

0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20377175
I should mention that the code I posted assumes you none of the people already exist in the database.
0
 

Author Comment

by:msyed1
ID: 20377419
Thanks for the code, I tried it....but I think Generics are only available in .Net 2.0 and above.  I am using Microsoft .Net Framework 1.1.
How can I do the comparison easily in .Net 1.1 ??
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20377540
Try using a system.collections.ArrayList instead.
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20556029
Forced accept.
modus_operandi
EE Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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