Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# & XML & nested loops problem (try 2)

C# & XML & nested loops problem (try 2)

Scheduled Pinned Locked Moved C#
helpdatabasecsharpsalesxml
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    (Previous can be deleted, my XML wasn't shown properly) Hello, I'm working on a C# console program. Now I've encountered the following problem: I read data from a MS-SQL database and create Article objects with this data (own class). An Article object exists out of the following members: custIDa, custIDb, docID, accountNr, tCode, tTarif, VAT. A customer can have multiple articles (so when custIDa is for example 1 it can have docID = 1 and docID = 2 (so 2 articles)). I add every Article object to an ArrayList (and maybe I'll sort it). What I want to accomplish is the following: I want to run through the ArrayList and write the Article-data to XML like this:`` `I think I'll have to do this with a nested loop, 1 to check if custIDa is the same or has changed and one for the docID's. So custIDa can occur multiple times with everytime a changed docID (you could state that it's a combined primary key as in SQL). Anyone can help me out with this or has any ideas to help me out 'cause I'm really stuck here :( Thanks in advance! PS: Sorry for my English, I'm from Belgium ;)` ``

    H 1 Reply Last reply
    0
    • A Anonymous

      (Previous can be deleted, my XML wasn't shown properly) Hello, I'm working on a C# console program. Now I've encountered the following problem: I read data from a MS-SQL database and create Article objects with this data (own class). An Article object exists out of the following members: custIDa, custIDb, docID, accountNr, tCode, tTarif, VAT. A customer can have multiple articles (so when custIDa is for example 1 it can have docID = 1 and docID = 2 (so 2 articles)). I add every Article object to an ArrayList (and maybe I'll sort it). What I want to accomplish is the following: I want to run through the ArrayList and write the Article-data to XML like this:`` `I think I'll have to do this with a nested loop, 1 to check if custIDa is the same or has changed and one for the docID's. So custIDa can occur multiple times with everytime a changed docID (you could state that it's a combined primary key as in SQL). Anyone can help me out with this or has any ideas to help me out 'cause I'm really stuck here :( Thanks in advance! PS: Sorry for my English, I'm from Belgium ;)` ``

      H Offline
      H Offline
      hooray
      wrote on last edited by
      #2

      I think it should be easier to do the selecting via sql. If can't send mulitple sql-statements to the db you should try to get your data into a local Datatable object. Then you can query it locally via the Select method.

      A 1 Reply Last reply
      0
      • H hooray

        I think it should be easier to do the selecting via sql. If can't send mulitple sql-statements to the db you should try to get your data into a local Datatable object. Then you can query it locally via the Select method.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Well I have to do it the way I described it and it all works, except for the writing to XML thingie... :( You can run through an ArrayList just like you run through a DataTable so it must be possible in a way. But that's just my problem, which way is the good way ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups