Wednesday, November 16, 2005

GetChildRows returns an array of DataRow objects from the child DataTable in a DataRelation. Unfortunately, the System.Web.UI databinding logic doesn't seem to realize that the data source might contain DBNull values if the data source isn't a DataView or DataTable. The end result is that StrongTypingException exceptions get thrown if my data contains any columns whose value is DBNull.Value. How to fix this?
You can use the msprop annotations in your typed dataset xsd file, so that the row accessors will return what you want instead of DBNull.Value. The reason you see the issue is because the datatable row accessors return DBNull.Value where as the strongly typed accessors expect the actual type to be returned and you have a conversion problem from DBNull to the actual type.For reference types [string etc.] returning “null” would be appropriate, but for value types [int etc] you need to assign a non-used value whenever DBNull.Value occurs.

You can check the following link for more information on these annotations.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp
However, from Whidbey we can use nullable generics.

No comments: