allow nulls in strongly typed data set asp.net

Discussion in 'ASP .Net' started by =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?=, Jun 14, 2006.

  1. 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?
    =?Utf-8?B?U2NvdHRfZnJvbV9DYXJlbWF0aWM=?=, Jun 14, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HardBap
    Replies:
    1
    Views:
    1,914
    Gabriel Lozano-MorĂ¡n
    Jun 30, 2005
  2. Replies:
    0
    Views:
    346
  3. Ted Ngo
    Replies:
    6
    Views:
    6,695
    jayeshkitukale
    Jun 20, 2008
  4. Keithb
    Replies:
    1
    Views:
    550
    LosManos
    Oct 25, 2006
  5. ThatsIT.net.au

    Strongly typed datasets ASP.NET

    ThatsIT.net.au, Mar 28, 2009, in forum: ASP .Net
    Replies:
    5
    Views:
    2,350
    Mr. Arnold
    Mar 28, 2009
Loading...

Share This Page