Help with copying multiple data in data element

Posted on 2014-08-03
Last Modified: 2016-02-18

I'm using the code below to copy first three characters in SCOUNTRY data to CAItem based on identical Item, but for some reason the code save the data in reverse order, for example CAN  is saved as ACN any ideas what is causing this problem? SCOUNTRY contains CAN 19911, but record is saved as ACN instead of CAN.

 Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
         Dim xdoc As XDocument = XDocument.Load(Application.StartupPath + "\Summary.xml")     
        Dim results = (From n In xdoc.Descendants("table1") Where n.Element("Item").Value <> "N/A"
                        Group n By n.Element("Item").Value Into agd4Group = Group
        Let sum = agd4Group.Select(Function(g) g.Element("SCOUNTRY")).Value.Substring(0, 3).OrderBy(Function(g) g).ToArray() _
                     From g In agd4Group _
                       Let summary = String.Join(",", sum) _
                       Select g, summary).ToList()

        '' Update the Summary node with the value of the summary string.                                                                                                                      
        results.ForEach(Sub(m) m.g.Element("CAItem").Value = m.summary)
        '' Save the document.                                                                                                                      
        xdoc.Save(Application.StartupPath + "\Summary.xml")

Open in new window


Question by:vcharles
    LVL 52

    Accepted Solution

    The OrderBy clause in your Linq query will be the issue. Because you have daisy-chained the commands in your query, you are actually calling OrderBy on the result of the SubString call - hence you get your string alphabetized.
    LVL 62

    Expert Comment

    by:Fernando Soto
    Victor can you post samples of the XML files to test with.

    Author Comment


    This issue has been resolved.


    LVL 62

    Expert Comment

    by:Fernando Soto
    Please close or have the question closed. Thanks.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now