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
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
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");
精彩评论