Set codegen:nullValue in your XSD and get... null?!

Yup. That's right. You've been a good boy (or girl) and annotated your typed dataset XSD with codegen:nullValue attributes to instruct the codegenerator in how to handle DBNull values. And you actually thought the MSDataSetGenerator would care? Well it does, if you add the minOccurs="0" aswell. Otherwise nothing happens.

Just to recap: codegen:nullValue takes four types of values:

codegen:nullValue="_throw" - default: throws an exception
codegen:nullValue="_empty" - returns String.Empty for string values, default constructed reference types and exceptions for value types.
codegen:nullValue="_null" - returns regular null for reference types. exception for value types
codegen:nullValue="replacement value" - A default value matching the type. For dates this format might be useful: "1980-01-01T00:00:0"


No Comments