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

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
LVL 18
vbturboAsked:
Who is Participating?
 
william007Commented:
Yeah...I have answer 3 as well in the above code
0
 
bman9111Commented:
not sure if this is what u wanted,

 dataset1.WriteXml("c:\filename.xml")
0
 
william007Commented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
vbturboAuthor Commented:
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
 
bman9111Commented:
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
 
bman9111Commented:
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
 
vbturboAuthor Commented:
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
 
bman9111Commented:
no problem, later...
0
 
william007Commented:
Actually, writeXML is more direct and is implicitly override the old file after tested...I just do it explicitly.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.