Quantcast
Channel: Remove duplicates nodes if it is repeating
Viewing all articles
Browse latest Browse all 2

Remove duplicates nodes if it is repeating

$
0
0

Hi,

I am trying to generate XML using LINQ Query below is my code trying to loop. But i want to remove the dupliactes if there is any repeated rows but i don't want to use distinct to remove the duplicates.   

   DataTable uniquecpemployees = meetingdetails.AsEnumerable()     // retriews 3 rows from 18 rows                       
                               .GroupBy(r => new { FirstName = r.Field<string>("CS FirstName"), LastName = r.Field<string>("CS LastName") })
                               .Select(g => g.First())
                               .CopyToDataTable();


                                var UniCptyEmployees = (from DataRow dr in meetingdetails.Rows select dr["FirstName"]).Distinct(); // retriews 2 rows from 18 rows


                                foreach (var itememp in UniCptyEmployees)
                                    {

                                       // var cptyemployees = (from DataRow dr in meetingdetails.Rows select dr["FirstName"]);
                                        DataTable cptyemployees = (from DataRow dr in meetingdetails.Rows
                                                                   where dr["FirstName"].ToString() == itememp.ToString()
                                                                         select dr).CopyToDataTable();

                                      


                                            if (!string.IsNullOrEmpty(uniquecpemployees.Rows[0]["CS FirstName"].ToString()))
                                            {

                                                    for (int k = 0; k < cptyemployees.Rows.Count; k++)
                                                    {

                                                        writer.WriteStartElement("CounterPartyEmployee");
                                                        writer.WriteAttributeString("FirstName", null, cptyemployees.Rows[k]["CS FirstName"].ToString());
                                                        writer.WriteAttributeString("LastName", null, cptyemployees.Rows[k]["CS LastName"].ToString());
                                                        writer.WriteFullEndElement();

                                                    }

                                               
                                            }
                                        }
Event IdMeeting IdFirstNameLastNameCS FirstNameCS LastName
7895668283462SESreeVasu
7895668283462SESreeVasu

Expected Output is it should rertiew 1 row:

78956       68283462  S    E     Sree    Vasu

Thanks

Sree


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images