开发者

How to load xml into a dataset in C#

private const String FormatOverrideCols = 
  "<XmlDS><table1><col1>Value1</col1></table1><t开发者_如何转开发able1><col1>Value2</col1></table1></XmlDS>";

System.IO.StringReader xmlSR = new System.IO.StringReader(FormatOverrideCols);
ds.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);

Why does this code snippet not load the data in the xml string into the dataset ??


Note the documentation on XmlReadMode.IgnoreSchema

Ignores any inline schema and loads the data into the existing DataSet schema. Any data that does not match the existing schema is discarded. If no schema exists in the DataSet, no data is loaded.

If you are going to ignore the schema, you need to match the existing dataset schema. Alter (or omit) your read mode if your goal is to use the schema from the XML directly.

using (StringReader xmlSR = new StringReader(FormatOverrideCols))
{       
     ds.ReadXml(xmlSR); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜