Typed DataSet Exception...

Kieron

Member
Joined
Nov 19, 2002
Messages
15
Location
England
Hi,

I keep getting the following error:

************** Start **************
System.Reflection.TargetInvocationException: Property accessor CompanyName
on object
CRMDataSet+Customer
sRow threw the following exception:Cannot get value because it is
DBNull. ---> System.Data.StrongTypingException: Cannot get value because it
is DBNull. ---> System.InvalidCastException: Cast from type DBNull to type
String is not valid.
at Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object
Value)
at
CustomersRow.get_CompanyName() in CRMDataSet.vb:line 1002
at
CustomersRow.get_CompanyName() in CRMDataSet.vb:line 1004
************** End **************

The column in question is allowed to have NULL values, and the records its crashing on has NULL values in the CompanyName column.
Ive tried re-generating the Customers section of the schema but nothing seems to work. The columns .AllowDBNull is True, so that shouldnt be an issue.

Can someone please explain whats going on!!
 
Horrible!

When the XML descriptions of the datatables are generated, these descriptions do NOT contain one specific attribute, which will allow for "isDBNull" Properties to be created.

Code:
<xs:element name="PRS_GUID" codegen:nullValue="_empty" type="xs:string" />

The "codegen:nullValue" part has to be added manually - or program a helper that will do it for you (At least I havent found a better way yet).

What we have done: Written a helper program which will add that attribute to the XML files.
 
Im not sure about the codegen:nullValue thing. I use the minOccurs property - set it to 0 to allow DBNull values. I would have thought this got put in if you created the table by dragging from server explorer, but havent it in awhile.

-Nerseus
 
Back
Top