المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem adding data from a data set to a List Object



C# Programming
10-02-2009, 11:31 AM
Hi

I have a method that takes in data from XML, puts it temporarily into a dataset, where I then add to a List Object. This bits ok, but where I am falling over, is where there is more than one item of data in an XML node. In my code I am using foreach to iterate through each node, and this is working because I am seeing loop through each element in the node. However, when I am adding it to the List Object, it is only adding the last node to the list rather than every element.

The structure of the xml is that the first two nodes can only have one set of data, but the last two can have one to many, and this is where it goes wrong. I did try mylist.add(adddata) at the end of the loop, but what happened was that the last item was added but repeated x number of times for the number of items in the data.

Can anyone show me a good answer to this problem?

Thanks