Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 316820 - Last Review: March 10, 2006 - Revision: 3.2
FIX: Cannot derive and extend a column in XSD with DataSet
This article was previously published under Q316820
This article refers to the following Microsoft .NET
Framework Class Library namespace:
On This Page
SYMPTOMS
When you try to read an Extensible Markup Language (XML)
schema into a
DataSet, the following duplicate name exception may be thrown when the
XML Schema Definition language (XSD) derives and extends a column definition:
An unhandled exception of type
'System.Data.DuplicateNameException' occurred in system.data.dll
Additional information: A column named 'column1' already belongs to this
DataTable.
If you handle this exception within a try/catch block,
you receive the following error message:
System.Data.DuplicateNameException: A column named 'column1' already belongs to
this DataTable.
CAUSE
The
DataSet is treating the column derivation and extension as if it were the
definition of an entirely new column, with the same name as an existing column.
RESOLUTION
To avoid this exception, define a new element type with the
attributes that you want, instead of deriving from and extending an existing
element type.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
This bug was corrected in Microsoft ADO.NET (included with the .NET Framework 1.1), and Microsoft Visual Studio .NET 2003, Professional Edition.
MORE INFORMATION
Steps to reproduce the behavior
- Create a new XSD file named Test.xsd. Paste the following
code into it:
<?xml version="1.0" standalone="yes"?>
<xsd:schema id="MyDataSet" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:complexType name="columns" abstract="true">
<xsd:sequence>
<xsd:element name="column1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="table1">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="columns">
<xsd:sequence>
<xsd:element name="column1" msdata:ReadOnly="True" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:schema>
- Create a new Visual Basic .NET console
application.
- Paste the following code into the sub Main of Module1:
Dim ds As New DataSet()
ds.ReadXmlSchema("C:\Test.xsd") 'Exception thrown here.
Console.Write("Schema Loaded Successfuly")
Console.Read()
- Change the string that is being passed in the call to
ReadXML to reflect the path to the XML file that you created.
- Press F5 to run and compile the application. You receive
the error message listed in the "Symptoms" section.
- In order to avoid this exception being thrown, replace code
in the XSD file with the following code that defines a new element with the
attributes that you want, instead of deriving from an existing element:
<?xml version="1.0" standalone="yes" ?>
<xsd:schema id="MyDataSet" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="table1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="column1" type="xsd:string" msdata:ReadOnly="True" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema> - Press F5 to run and compile the application. Output to the
console confirms that the XSD schema was loaded successfully. Press ENTER to
stop the running application, and then close the Console window.
REFERENCES
For more information about XML integration with
ADO.NET, click the following article number to view the article in the Microsoft Knowledge Base:
313649Â
(http://kbalertz.com/Feedback.aspx?kbNumber=313649/
)
Roadmap for XML integration with ADO.NET
For more information about XML schemas in the .NET
Framework, click the following article number to view the article in the Microsoft Knowledge Base:
313826Â
(http://kbalertz.com/Feedback.aspx?kbNumber=313826/
)
Roadmap for XML schemas in the .NET Framework
APPLIES TO
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Studio .NET 2002 Professional Edition
| kbbug kbfix kbnofix kbsystemdata kbinterop kbvs2002sp1sweep KB316820 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please