Help with copying multiple data in data element

Hi,

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


Thanks,

Victor
vcharlesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
Victor can you post samples of the XML files to test with.
0
vcharlesAuthor Commented:
Hi,

This issue has been resolved.

Thanks,

Victor
0
Fernando SotoRetiredCommented:
Please close or have the question closed. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.