How to handle Null values in a database?

When using the data set designer to interface with an Access database, the auto-generated code insists on throwing an exeption every time a field contains a Null value, before I can handle the Null in my "own" code.

I can get around it by modifying the auto-generated code, but this gets overwritten every time i change something...

How to get around this I have tried the "workaround" suggested at the end of this post

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=144980&SiteID=1

but it simply doesn't work for me - I get an exeption anyway.

There must be others with the same problem out there - any help



Answer this question

How to handle Null values in a database?

  • T-off

    A more relevant question would probably be "What is the auto-generated code doing that prevents me from retrieving a null value from the database "

    The problem should be easily replicated:-

    Create a simple Access database, with a field that is nullable (that is, some records have data in the field, others contain null).

    Try to display the data in the field if the record contains any, otherwise display nothing (using the built-in table adapter / data set system)

    Any help greatly appreciated!

    This is my actual code:-

    Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick

    Dim ss As Integer

    Dim Detaildataset As New CompetenceMaster.masterDataSet

    ss = Me.ListView1.SelectedIndices(0)

    Me.TblRequirementsTableAdapter1.FillByRequirement(Detaildataset.TblRequirements, ListView1.Items(ss).SubItems(1).Text())

    'The auto-generated code throws an exeption before this point if the value of RqDescription is null in the database, so the next line never gets executed

    If Detaildataset.TblRequirements(0).RqDescription() <> Nothing Then RichTextBox1.Text = Detaildataset.TblRequirements(0).RqDescription() Else RichTextBox1.Text = ""

    End Sub

     

     


  • pushart

    Could you provide a few more details Such as, what your code is doing when the exception is generated

  • How to handle Null values in a database?