C# & XML & nested loops problem (try 2)
-
(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 ;)` ``
-
(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 ;)` ``
-
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.
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 ;)