Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-11-29
6
Medium Priority
?
155 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:
Joel Coehoorn 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:Joel Coehoorn
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:Joel Coehoorn
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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