DataSet XML export is empty
I've got in-memory dataset with couple of tables that is populated in code. Data-bound grids on the gui show table contents without a problem.
Then I try to export the dataset into XML:
ds.WriteXml(fdSave.FileName, XmlWriteMode.WriteSchema);
and get empty XML (with couple of lines regarding dataset names but without any tables)
If I export table directly I've got all the data but dataset name is obviously wrong:
ds.Fields.WriteXml(fdSave.FileName, XmlWriteMode.开发者_StackOverflowWriteSchema);
What am I missing? Is there any reasonable way to write the whole dataset into file?
ok, silly me. was clearing dataset tables collection before populating it...
Have a look at the documentation on DataSet.WriteXml:
http://msdn.microsoft.com/en-us/library/ms135425.aspx
and on XmlWriteMode:
http://msdn.microsoft.com/en-us/library/system.data.xmlwritemode.aspx
Try using XmlWriteMode.IgnoreSchema. The docs say for XmlWriteMode.WriteSchema "If the DataSet does not have a current schema, nothing is written."
you must add the data tables to your dataset like, ds.Tables.Add(datatable1);
then write export it into the schema
精彩评论