Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
How to save multiple dataset to a single xml.
when i try the below code its overwriting and i am getting only one dataset value

StreamWriter xmldoc = new StreamWriter(HttpContext.Current.Server.MapPath("123.xml"), false);
           ds.WriteXml(xmldoc);
           ds1.WriteXml(xmldoc);


Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 4-Feb-12 3:29am    
Looks like a bad idea. Your code won't give you well-formed XML.
--SA
Lancy.net 4-Feb-12 3:38am    
hi i need your valuable suggestion how do i do this please?

If you're using WriteXml method the latter write operation overwrites the contents of previously created file.

Before writing the dataset to the file, could you merge the datasets and write the merged dataset. See: DataSet.Merge[^]
 
Share this answer
 
Comments
Lancy.net 4-Feb-12 3:37am    
Thanks Mika let me try....
Not that it is impossible; rather, the question is not fully specified. The method you try to use will create some text which is never represents a well-formed XML, just because concatenation of two XMLs is not a well-formed XML.

You need some "outside" XML schema which would provide a container for two or more different XMLs each corresponding to the portion of two or more unrelated data sets (if they are related, you data model is wrong in first place). This schema is something arbitrary. You don't specify how do you want to store more then one data sets in your XML container, so it can be done in many similar ways.

Most likely, the whole idea is wrong. If you need two data sets in one XMLs, why are two different data sets? They should be one united data set. If this simple principle is not in line with your data model, it means your data model is wrong in first place. Try to prove me wrong though…

—SA
 
Share this answer
 
v2
Comments
Lancy.net 4-Feb-12 3:45am    
Hi Thanks for your comment...i want to use this to print invoice pdf using iTextsharp...
Reason for many dataset is Header,Footer,Item Details,Address..
I am planning to bring all in one xml then to print pdf..
for this purpose you must write an alogrithm for generating xml document dynamically... see how to write xml formate form dataset and make it in loop
 
Share this answer
 
Comments
Tim Corey 26-Jun-12 13:08pm    
Your answer does not really add to the solution and it comes four months after the question was asked.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900