Set dataset element default value to empty string


M

moondaddy

I'm using vb.net 1.1 and VS2003. in the dataset designer I'm trying to set
the default value of a dataset table column (actually its an attribute) to
an empty string so I don't get dbnull error in my code. How can I do this.
In databases I can set a default value of empty string by using 2 quotes
("") but if I do that here the return value is literally 2 quotes ("""").
Any good ideas?

Thanks.
 
Ad

Advertisements

K

Kevin Yu [MSFT]

Hi moondaddy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to set the default value of a
DataColumn to an empty string at design time. If there is any
misunderstanding, please feel free to let me know.

This can be achieved by setting the default attribute for the column. Here
are the steps:

1. In the DataSet Designer, switch to XML view for the DataSet.
2. Find the element for the corresponding column. For example, I'm going to
set default value for a column named "ShipName". The element in the schema
might look like the following:
<xs:element name="ShipName" type="xs:string" minOccurs="0" />
3. Now we add the default attribute to the element, using default="".
<xs:element name="ShipName" type="xs:string" minOccurs="0" default ="" />

Now the default value has been set to an empty string.

For more information, please check the following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/
xsd_ref_9ugk.asp

HTH. If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
M

moondaddy

Thanks that work really good. I don't know why I didn't think of that.
 
K

Kevin Yu [MSFT]

Hi moondaddy,

You're welcome. Thanks for sharing your experience with all the people
here. If you have any questions, please feel free to post them in the
community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Ad

Advertisements

Joined
Apr 14, 2011
Messages
1
Reaction score
0
Hi All,

I used following xsd

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Rules">
<xs:complexType>
<xs:sequence>
<xs:element name="Rule" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="username" type="xs:string" minOccurs="0" default =""/>
<xs:element name="password" type="xs:string" minOccurs="0" default =""/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>


when I try to print the user name value I am getting null values
could you please suggest me on this
 
Ad

Advertisements


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