views:

315

answers:

2

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

A: 

You have to write with schema included.

ds.WriteXml("TEST.xml", XmlWriteMode.WriteSchema);

edit:

or

ds.Tables[0].WriteXml("TEST.xml", XmlWriteMode.WriteSchema);
ds.Tables[0].ReadXml("TEST.xml");

or strongly typed datatable read/write

typedDataset.tableName.WriteXml("TEST.xml", XmlWriteMode.WriteSchema);
typedDataset.tableName.ReadXml("TEST.xml");
sadboy
Are you saying that the XML which I am reading from (which was created from a dataset.WriteXML()) has to include the schema?
Saif Khan
Yeah, I've run into it before. If you don't write the schema when you write it to disk, then it won't just read back in. I'm sure there is a way to give it the scheam on read or the infer, but it's just easiest to write the schema in the first place.
sadboy
It loads this time but it ads a second table with the data and ignore the TypedTable created in the Visual Studio XSD dataset designer.
Saif Khan
you understand that I am trying to load a dataset into a typeddataset...right?
Saif Khan
+1  A: 

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
Saif Khan