DataReader to XML File

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.
 
A

Alex Feinman [MVP]

How about reading all three tables into a dataset (using 3 calls to
SqlCeDataAdapter.Fill) and then calling DataSet.WriteXml()?
 
N

Nestor Acha

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....
 
N

Nestor Acha

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>
 
A

Alex Feinman [MVP]

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.
 
J

Jon Skeet [C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

XML Dataset Datareader 2
Load From XML 1
XML to SQLce 4
Xml to SqlCe 2
How to manage XML database ? 1
Having a database issue 0
DataReader Output as XML 2
Importing xml woes 1

Top