[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 26
  • Last Modified:

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
0
vcharles
Asked:
vcharles
  • 2
1 Solution
 
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
 
Fernando SotoCommented:
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 SotoCommented:
Please close or have the question closed. Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now