views:

619

answers:

3

I'm working on a product feature that will allow the user to export data from a SQL CE database on one copy of my application and re-import it into SQL CE on the other end. This data is not whole tables, but the result of queries.

I had hoped to take advantage of .net's built-in XML-based serialization like in DataTable.WriteXML. But, none of the methods for executing queries against a SqlCeCommand provide an obvious way of serializing to XML or extracting a DataTable, which could provide the method.

Is there something I'm missing? Do I have to write my own serialization-deserialization methods or is there a built-in way.

A: 

I would think you could retrieve the data to a DataSet, call WriteXML on it, and then on the other end declare a new DataSet and call ReadXML on it.

Grank
+1  A: 

You want to create an SqlCeDataAdapter and use it .Fill() a dataset. Then serialize the entire dataset via it's .WriteXml() method.

Joel Coehoorn
+4  A: 

Assuming cmd is your SqlCeCommand....

using(var dr = cmd.ExecuteReader())
{
   DataSet ds = new DataSet();
   DataTable dt = ds.Tables.Add();
   dt.Load(dr);
   ds.WriteXML(...);
}
Jonathan