none
Finding Duplicated Emails and marging the rows from datatable RRS feed

  • Question

  •  

    Hello All

     

    I have a DataTable.

    The DataTable contains a few colums.. ClientID, ListID, EmailID, Email, FirstName, LastName, Address, etc..

    What i am trying to do with Linq is look for duplicated Email's .

    When found i want to merge the two duplicated email rows to ONE row based on the FIRST row found. If one of them contains NULL it will be filled.

     

    if my table is like this:

    ClientID, ListID, EmailID, Email,             FirstName, LastName

       1            2       5          xyz@a.com      david          NULL

       1            2       6          abc@s.com      michal       gerferson

       1            2       7          xyz@a.com      candy        sisia

     

    the result will be:

    ClientID, ListID, EmailID, Email,             FirstName, LastName

       1            2       5          xyz@a.com      david          sisia

       1            2       6          abc@s.com      michal       gerferson

     

    as you can see david overrided candy since it was first accourd. and sisia LastName replaced the NULL..

     

    I can't seem to find a way to make it with LINQ Sad

    If anyone know how please show me an exanple..

    I am using C# with FrameWork 3.5

     

     

     

     

    Tuesday, March 11, 2008 10:06 AM

Answers

  • It sounds like you want to query the rows and group them by email.  Then for each group  you want to write some logic to resolve the set down to one row (merging the data into the first row and removing the others from the table).

     

    LINQ can help you with the query part, but you are on your own for the removing & resolving down to one row part.

     

     

     

    Wednesday, March 12, 2008 11:34 PM
    Moderator