Blank default in XSD

  • Thread starter Thread starter mjwills
  • Start date Start date
M

mjwills

All,

I am using VB.NET 1.0 / 2002. I am having trouble setting a column
default to "" (note that "" is not the same as Null / DBNull / Nothing)
in a typed dataset (to reflect the same database default)...

Below is a snippet...

<xs:element name="Customers">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:string"
default="bob" />
<xs:element name="CompanyName" type="xs:string"
default="" />
<xs:element name="ContactName" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

If I run the below code:

Dim x As New Dataset1()

Dim y As New Dataset1.CustomersDataTable()

Dim z As Dataset1.CustomersRow = y.NewCustomersRow()

y.AddCustomersRow(z)

I get an error (Column CompanyName does not accept nulls). If I change:

<xs:element name="CompanyName" type="xs:string"
default="" />

to:

<xs:element name="CompanyName" type="xs:string"
default="Bob" />

the problem goes away (ie it correctly handles every value EXCEPT ""
(blank string)).

So my question is - how do I change the XML to reflect the fact that
the column is Required (NOT NULLable) AND has a default of "" (empty
string - not Null / DBNull / Nothing)?

Or, to state the question differently, how do I get VB.NET to put the
following line in the InitClass of the xxxDataTable class:

Me.columnCompanyName.DefaultValue = ""

(I know I can put it there myself, but then as soon as I change the XML
and regenerate the VB.NET code for the dataset my change will be lost).


I don't want to use nillable="true" since that will make it look as if
the column is NULLable (when it isn't).

Thanks
Matthew Wills
 
MJWills,

I never use that myself however because that you have no answer.

Can you not make your own class, where you Inherit that created strongly
typed dataset and than override the methode where you need that setting and
set that default there

Just a thought,

Cor
 
Cor,

That would work - thanks for that suggestion.
Any other approach that doesn't involve inheritance?

Thanks
Matthew
 

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

Back
Top