allow nulls in strongly typed data set asp.net

G

Guest

I'm trying to use a strongly typed dataset in my asp.net (2.0) project with
visual studio 2005. I have generated the dataset and tableadapters in the
designer. I'm using SQL server EE 2005 as the database.

One of my tables has a guid field that has the "allow NULL" property in the
database. If I create a <typed>datatable, then try to add a row to the new
table, passing the value DBNULL.value as the field value in question, then I
get the exception System.Data.StrongTypingException("The value for column ...
is DBNULL.

If I go back and look at the generated code, it looks like the designer
generates code to throw these exceptions for those fields with "allow NULL",
and not for those that don't allow NULL. Isn't this exactly backwards?

More concretely: I have a field picture_id of type guid which, in the
database, allows NULL values.

if I look at the xml that's generated by the dataset designer, that
particular field looks like this:

<Parameter AllowDbNull="True" AutogeneratedName="" DataSourceName=""
DbType="Guid" Direction="Input" ParameterName="@picture_id" Precision="0"
ProviderType="UniqueIdentifier" Scale="0" Size="0" SourceColumn="picture_id"
SourceColumnNullMapping="False" SourceVersion="Current"> </Parameter>

All looks fine so far, but if I then look at the actual VB generated by VS
2005, it looks like this:

Public Property picture_id() As System.Guid
Get
Try
Return
CType(Me(Me.tablepeople.picture_idColumn),System.Guid)
Catch e As System.InvalidCastException
Throw New System.Data.StrongTypingException("The value
for column 'picture_id' in table 'people' is DBNull.", e)
End Try
End Get
Set
Me(Me.tablepeople.picture_idColumn) = value
End Set
End Property

Which, again, seems EXACTLY BACKWARDS???? Shouldn't "allow NULL" mean
"handle NULL gracefully"? And "don't allow NULL" mean "generate a
catastrophic error (i.e., throw an exception) if NULL occurs"???

Just for reference, other fields that don't have "allow NULL" checked don't
have the code to generate the exception...

Any ideas? Am I suffering from a cranial inversion of some kind?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top