Import/export by using DataSet WriteXml and ReadXml

By ramon
September 2, 2008
1

I just tried to create a simpel import/export feature in one of our applications based on XML. My first thought was: Create a typed dataset and for export just serialize it to XML with the WriteXml method and for import deserialize it by using ReadXml.

Well the write part created exactly the file that I wanted but the ReadXml did not work as expected. No exceptions occured but no data was read so I could not add the data to the database. I remembered that I probably had to do with a schema option. Either at the write or the read. I wanted the write to behave like it was doing now. So browsing MSDN gave me the answer that I had to use the XmlReadMode.InferSchema parameter to the ReadXml method. That uses typed dataset information to check for data consistency.

So now my simple import/export is working again and it appears that my (typed) dataset knowledge was a bit rusted by not using it for quite a while.

Comments: 1

  1. Andy says:

    I’ve been trying to do this but it it just refuses to read the data back into my dataset!

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Recent Posts
  • Recent Comments
  • Archives
  • Categories
  • Meta