CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: handling DBNULL

  1. #1
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    handling DBNULL

    Hi All,

    I have a column on an SQL Server DB that is declared as type integer and is nullable.

    I have a query that includes this column that is bound to a typed dataset.

    This is the Typed Dataset's Property

    Code:
                <Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _
                Public Property RateableValue() As Integer
                    Get
                        Try
                            Return CType(Me(Me.tableCustomerSystemFieldsAssetLocation.RateableValueColumn), Integer)
                        Catch e As Global.System.InvalidCastException
                            Throw New Global.System.Data.StrongTypingException("The value for column 'RateableValue' in table 'CustomerSystemFieldsAssetLocation'" & _
                                    " is DBNull.", e)
                        End Try
                    End Get
                    Set(ByVal value As Integer)
                        Me(Me.tableCustomerSystemFieldsAssetLocation.RateableValueColumn) = value
                    End Set
                End Property
    How do I test for a null value against this or should I change the code above. As soon as It hits the row:

    Code:
    Return CType(Me(Me.tableCustomerSystemFieldsAssetLocation.RateableValueColumn), Integer)
    My app crashes with conversion error DBnull to integer.
    If you find my answers helpful, dont forget to rate me

  2. #2
    Join Date
    Dec 2003
    Location
    Northern Ireland
    Posts
    1,362

    Re: handling DBNULL

    Is tableCustomerSystemFieldsAssetLocation a row from the datatable? If so, check whether Me.tableCustomerSystemFieldsAssetLocation.IsNull("RateableValueColumn") is true before getting the value.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook


    0100 1101 0110 1001 0110 0011 0110 1000 0110 0001 0110 0101 0110 1100 0010 0000 0100 0101 0110 1100 0110 1100 0110 0101 0111 0010

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured