Search code examples
.netxmldatasetstrongly-typed-dataset

Loading an typed dataset from an XML document


I am unable to fill a typed dataset

Using reader as New StringReader(My.Resources.sampledata)
  typedDataset.ReadXML(reader)
  'typedDataset.WriteXML("c:\data.xml")
End Using

The above does not work. If I enable the commented line to write the results to file I get a 1K file with

<?xml version="1.0" standalone="yes"?>
<testSchema xmlns="http://tempuri.org/TestSchema.xsd" />

If I create a blank dataset liek this

Dim data as New DataSet
    Using reader as New StringReader(My.Resources.sampledata)
  data.ReadXML(reader)
  'data.WriteXML("c:\data.xml")
End Using

It writes data to the file. Which means that the dataset is loaded from the XML. The XML was created from a valid dataset

Dim ds as DataSet = Service.GetData(params)
ds.WriteXML(C:\sampledata.xml")

and then stored in the Resources file.

I also tried the options

1. Auto
2. ReadSchema
3. IgnoreSchema
4. InferSchema

With "InferSchema" I was able to add the XML but it created a second table.

All I want to do is load my Typed Dataset from an XML document which was created from dataset.WriteXML()

Thanks


Solution

  • Solution

    Dim ds As New DataSet
    Using reader As New System.IO.StringReader(My.Resources.sampledata)
          ds.ReadXml(reader)
          typedDS.Load(ds.Tables(0).CreateDataReader(),
                       LoadOption.OverwriteChanges,
                       typedDS.MyTable)
    
    End Using