Wednesday, October 17, 2007

Typed DataSet NullValue behaviour

The default value for NullBehaviour in a typed DataSet in Visual Studio 2005 is to throw an exception. I recently needed to change this in a dataset containing 50 tables. Rather than edit it manually I edited the .xsd file using xml Notepad. I found a post on MSDN that indicated what needed changing:

msprop:nullValue="_empty" -- (Empty)

msprop:nullValue="_null" -- (Nothing)

msprop:nullValue="_throw" -- (Throw exception)

msprop:nullValue="_throw" is the default value and it is not persisted by default.

The xpath queries I used were:

--Find string columns with no null value prop
/xs:schema/xs:element/xs:complexType/xs:choice/xs:element/xs:complexType/xs:sequence/xs:element[(child::xs:simpleType/xs:restriction/@base='xs:string') and (not(@msprop:nullValue))]


--Find nodes where value exists and is not '_empty'


No comments: