Cannot read XML into data set

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am trying to read in an XML file into a strongly typed data set, and I get
this error:
Column name 'myColumn' is defined for different mapping types.

Here is my code:
myDataSet.ReadXml("myFile.xml", XmlReadMode.InferTypedSchema);

Here is my XML:
<?xml version="1.0" encoding="utf-8" ?>
<myRoot>
<myTable myColumn="test data 1" />
<myTable myColumn="test data 2" />
<myTable myColumn="test data 3" />
</myRoot>

To simplify it, I removed all constraints and relations on myTable in the
XSD designer, so the table is laid out like this:
myColumn {string, allow nulls, null value = empty}
myColumn2 {string, allow nulls, null value = empty}

Any ideas what the problem is?

Thank you,

Eric
 
Eric,

Your dataset has attributes. A dataset has no attributes, in your case I
would try it first to open the xml file in the IDE from VS.

Cor
 
Hello Cor,

Thank you for the reply. I am not sure what you mean by "Your dataset has
attributes. A dataset has no attributes".

It is my understanding that when using the ReadXml method, all of the root
node's elements from the XML doc are imported into the DataSet's DataTable,
translating all XML attributes and sub elements into DataColumns.

I of course can get this to work using untyped DataSets, but I'd like to
avoid that if possible. Also, I did successfully open the XML in the VS IDE
as you suggested.

(And congratulations on earning MVP; your posts have helped me tremendously
over the years!)

Thanks again,

Eric
 
Eric,

All just to try, as most of us here am I seldom using a 1.x typed dataset,
but are you not able to merge your untyped dataset as you get it with its
elements, into your typed dataset. The typed one should inherits an untyped
on. Therefore the elements (columnames) should be of course the same.

Cor
 
Back
Top