DataSet.ReadXml

K

keikoo

Hi, I,m trying to fill a DataSet with a xml file, so I pretend to use
the ReadXml method.
The .xsd file is defined, and the fields of the xml file have the same
name and type than the DataTable inside the DataSet.

the method is invoked in than way:

System.Xml.XmlNodeReader _xmlreader=new
System.Xml.XnodeReader(XmlDocument);
_dataset.ReadXml(_xmlreader, System.Data.XmlReadMode.ReadSchema);
_xmreader.Close();

The code is executed without exceptions, but the datatable remains the
same, no rows were added. If I change the reading options to
InferSchema, an exception is thrown because it tries to create new
columns with the same name as existing ones, so I think, the schema is
well created with the correct fields, the same as the xml file.

If I change the reading option to IgnoreSchema I have the same result
than with InferSchema.
Anyone knows what I'm doing wrong?. I've got no much idea about xml
schemas.

Thanks in advance.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Did you check if a new table was created?

I have never read XML to an already created table, so the only thing I can
assure you is that it does work when the dataset is empty.

Did you see this in MSDN:
If the XSD schema for a DataSet includes a targetNamespace, data may not be
read,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top