Set dataset element default value to empty string

Discussion in 'Microsoft ADO .NET' started by moondaddy, Mar 25, 2004.

  1. moondaddy

    moondaddy Guest

    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.

    --
     
    moondaddy, Mar 25, 2004
    #1
    1. Advertisements

  2. 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."
     
    Kevin Yu [MSFT], Mar 25, 2004
    #2
    1. Advertisements

  3. moondaddy

    moondaddy Guest

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

    --

    "Kevin Yu [MSFT]" <> wrote in message
    news:...
    > 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."
    >
     
    moondaddy, Mar 25, 2004
    #3
  4. 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."
     
    Kevin Yu [MSFT], Mar 25, 2004
    #4
  5. Kevin,

    According to Microsoft Knowledgebase Article 325691, the default value
    element is not serialized. I tried the same with no result using Visual
    Studio 2003.

    Reference: http://support.microsoft.com/default.aspx?scid=kb;en-us;325691

    Best regards,

    Benny Tordrup

    "Kevin Yu [MSFT]" <> skrev i en meddelelse
    news:...
    > 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."
    >
     
    Benny Tordrup, Mar 29, 2004
    #5
  6. moondaddy

    amadupat

    Joined:
    Apr 14, 2011
    Messages:
    1
    Likes Received:
    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
     
    amadupat, Apr 14, 2011
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anton Sommer
    Replies:
    5
    Views:
    1,036
    Anton Sommer
    Aug 27, 2003
  2. Guest
    Replies:
    1
    Views:
    1,607
    W.G. Ryan eMVP
    Nov 9, 2004
  3. itzik
    Replies:
    9
    Views:
    548
    Guest
    Feb 15, 2005
  4. Replies:
    1
    Views:
    1,657
    Guest
    Sep 7, 2006
  5. BillE
    Replies:
    1
    Views:
    1,180
    Scott M.
    Apr 25, 2008
Loading...

Share This Page