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
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