Hi Oleg,
I have to admit, I stared at this for a while without seeing it, but the
solution is fairly simple.
<xs:complexType name="SchedulingMethodType">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Interval" type="xs:duration" minOccurs="0"
maxOccurs="1" />
<xs:element name="DailyAt" type="xs:duration" minOccurs="0"
maxOccurs="1" />
</xs:choice>
</xs:complexType>
Notice the minOccurs attribute for the Interval and DailyAt elements inside
the choice element. When you load this schema into a dataset, the column
definitions in the table will be specified with "allowNull" and
"AllowDBNull" both set to True. Without setting minOccurs to 0 (zero), the
"allowNull" and "AllowDBNull" properties are set to false.
I hope this helps.
Brooks
[MSFT]
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/copyright.htm.
"Oleg Ogurok" <ol**@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10*************@corp.supernews.com...
Hi all,
I have a complex type defined as follows:
<xs:complexType name="SchedulingMethodType">
<xs:choice maxOccurs="1">
<xs:element name="Interval" type="xs:duration" />
<xs:element name="DailyAt" type="xs:duration" />
</xs:choice>
</xs:complexType>
When I use this type in XML, I want to specify either <Interval> or
<DailyAt> but not both, hence the use of <xs:choice>. However, when I
create a DataSet generated by VS.NET 2003, and try to load my XML file with
.Read(), I get System.Data.ConstraintException Failed to enable
constraints. It seems the framework tries to load both values. So when I use something
like this:
<SchedulingMethod>
<Interval>PT30M</Interval>
</SchedulingMethod>
The error tells that value DailyAt is missing (i.e. it throws
InvalidCastException trying to convert null into TimeSpan).
Am I doing something wrong? Doesn't <xs:choice> mean "only one from the
list" ?
Thanks in advance,
-Oleg.