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

x
?
Solved

Export/write all content in a dataset to a xml file

Posted on 2005-05-15
9
Medium Priority
?
236 Views
Last Modified: 2010-04-23
Hi all

Im useing vs VB.NET

1)How can i export all data in a dataset into a xml file ?
2)and if the xml file does not exist then how do i create one ?
3)and if the  xml file exists how do i over write it....in case the datasets content has changed ?

rgds vbturbo
0
Comment
Question by:vbturbo
  • 4
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:bman9111
ID: 14007641
not sure if this is what u wanted,

 dataset1.WriteXml("c:\filename.xml")
0
 
LVL 9

Expert Comment

by:william007
ID: 14007644
1 and 2)
First of all Imports System.io
then following code achieve your objective
    Dim fsobject As New FileStream("ToDo.xml", FileMode.Create) 'FileMode.Create is equivalent to requesting that if the file does not exist,
        'use CreateNew; otherwise, use Truncate
        Dim mywriter As New StreamWriter(fsobject)
        mywriter.WriteLine(lobjdataset.GetXml)'lobjdataset is the variable name of the dataset
        mywriter.Close()
        fsobject.Close()
0
 
LVL 9

Accepted Solution

by:
william007 earned 1000 total points
ID: 14007647
Yeah...I have answer 3 as well in the above code
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Author Comment

by:vbturbo
ID: 14007664
HI bman9111

thanks for quick reply

just one more question.... forexam i saved data to the xml.file  and then later on i save data in the same  xml.file again, can i then be sure that the previuos data
is erased or overwritten so i wount get any mixed data in the xml.file

rgds vbturbo
0
 
LVL 8

Expert Comment

by:bman9111
ID: 14007689
file should be overwritten if not use

dim f as file
if f.exists("C:\xmlfile.xml") = true then
f.delete("c:\xmlfile.xml")
end if
0
 
LVL 8

Expert Comment

by:bman9111
ID: 14007692
guess I didn't understand what u wanted I use the dataset1.WriteXml("c:\filename.xml")
all the time and never have problems....glad to see u got what u wanted..
0
 
LVL 18

Author Comment

by:vbturbo
ID: 14007712
Thanks a lot

i wanted to split the point's a bit but was a little to quick

I owe you one ...next time

Many rgds vbturbo
0
 
LVL 8

Expert Comment

by:bman9111
ID: 14007727
no problem, later...
0
 
LVL 9

Expert Comment

by:william007
ID: 14007761
Actually, writeXML is more direct and is implicitly override the old file after tested...I just do it explicitly.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question