Error: Cannot have more than one SimpleContent columns in a DataTable.

D

dlgarrett_98

Error: Cannot have more than one SimpleContent columns in a DataTable.

I have a small XML document which I want to convert to a Net20 DataSet.
I use the .Net xsd tool to do this, and it works fine. I can load the
DataSet with data and print out the DataSet, and that works fine. But
when I try to copy the DataSet using DataSet.Copy(), I get an error.
Am I doing something amiss, or is this a bug in .Net.

Thanks!


My Xml document:


<?xml version="1.0" encoding="utf-8" ?>
<Book>
<Author>
<Name></Name>
<Address>A</Address>
<Address>A</Address>
</Author>
</Book>


My generated XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Book" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Book" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Author">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0" />
<xs:element name="Address" nillable="true" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="Address_Text"
msdata:Ordinal="0">
<xs:extension base="xs:string">
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>


My program:

using System;
using System.Data;

class Program
{
static void Main(string[] args)
{

Book aBook = new Book();

Book.AuthorRow autRow = aBook.Author.NewAuthorRow();
autRow.ItemArray = new object[] { "My Name", "1" };
aBook.Author.AddAuthorRow(autRow);

Book.AddressRow aRow = aBook.Address.NewAddressRow();
aRow.ItemArray = new object[] { "My Address" , "1" };
aBook.Address.AddAddressRow(aRow);

Book.AddressRow bRow = aBook.Address.NewAddressRow();
bRow.ItemArray = new object[] { "My Address2", "1" };
aBook.Address.AddAddressRow(bRow);

aBook.WriteXml(Console.Out);

try
{
DataSet ds = aBook.Copy();
}
catch ( Exception exc )
{
Console.WriteLine( "\n{0} \n{1}", exc.Message,
exc.StackTrace );
}
}
}


My output:

C:\DotNet\TestApp\TestInterface\bin\Debug>TestInterface
<Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Author>
<Name>My Name</Name>
<Address>My Address</Address>
<Address>My Address2</Address>
</Author>
</Book>
Cannot have more than one SimpleContent columns in a DataTable.
at System.Data.DataColumnCollection.AddAt(Int32 index, DataColumn
column)
at System.Data.DataTable.CloneTo(DataTable clone, DataSet cloneDS,
Boolean sk
ipExpressionColumns)
at System.Data.DataTable.Clone(DataSet cloneDS)
at System.Data.DataSet.Clone()
at Book.Clone() in C:\DotNet\TestApp\TestInterface\aDoc.cs:line 85
at System.Data.DataSet.Copy()
at Program.Main(String[] args) in
C:\DotNet\TestApp\TestInterface\Program.cs:
line 27
 

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