Solved

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

Posted on 2007-11-29
6
152 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 500 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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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