DataReader to XML File

  • Thread starter Thread starter David Webb
  • Start date Start date
D

David Webb

Hi,

What is the easiest way to output the contents of a datareader into an
XML file? I have an SQLCe Database and need to export the contents of
each table (forward only) to a single XML file. Each table has about 3
fields in it, so I want the XML to have the TableName, followed by the
3 fields of data. Therefore, the XML file will ultimately contain 6
tables each containing 3 fields with perhaps 20 rows of data.

I just need to read a table, append to the XML, read a table, append
to the XML etc....

Any simple code snippets would be greatly appreciated.

Many thanks in advance for your assistance.

Kind Regards,

David.
 
How about reading all three tables into a dataset (using 3 calls to
SqlCeDataAdapter.Fill) and then calling DataSet.WriteXml()?
 
I have problems using datasets for this purpose. If the tables or queries
return a lot of data (around 1000 records with 15 fields) it consumes all
the memory from the pocket pc and sometimes blows up the application. I use
datareader for each table and create manually using WriteElementStrings.
Remember the memory in the pocket is too short and datasets doesnn't dispose
until you finish the program.
I try to use GC, Idisposable interfaces and Dataset gave me a bad memory
performance in my pocket pc programs.

Nestor

PD. If somebody knows how to dispose this datasets objects please let us
know....
 
I forgot...
for me would be better to use a datareader for each table
and create a big output xml tag like this..

<Output>
<table1>
<Record1>
<R1Field1></R1Field1>
<R1Field2></R1Field2>
<R1Field3></R1Field3>
</Record1>
<table1>
<table2>
<Record2>
<R2Field1></R2Field1>
<R2Field2></R2Field2>
<R2Field3></R2Field3>
</Record2>
<table2>
</Output>
 
I agree - for large datasets or if custom xml format is required, the way to
go is to iterate through DataReader and use XmlWriter to output nodes one by
one.
 
Nestor Acha said:
I have problems using datasets for this purpose. If the tables or queries
return a lot of data (around 1000 records with 15 fields) it consumes all
the memory from the pocket pc and sometimes blows up the application. I use
datareader for each table and create manually using WriteElementStrings.
Remember the memory in the pocket is too short and datasets doesnn't dispose
until you finish the program.

When you say "datasets don't dispose until you finish the program",
could you elaborate? Is there some issue with garbage collection of
datasets in the CF?
 
Back
Top