I keep getting a NullReferenceException. Any help would be great!

    Private Sub fillpub(ByVal argPubID As Integer)

        Dim drpub As _books_Fall2012_A2DataSet.PublishersRow
        drpub = _books_Fall2012_A2DataSet.Publishers.FindByPubID(argPubID)

        If drpub.IsNameNull Then

            txtPublisher.Text = ""
        Else
            txtPublisher.Text = drpub.Name
        End If

        If drpub.IsAddressNull Then
            txtAddress.Text = ""
        Else
            txtAddress.Text = drpub.Address
        End If


        If drpub.IsCityNull Then
            txtCity.Text = ""
        Else
            txtCity.Text = drpub.City
        End If


        If drpub.IsStateNull Then
            txtState.Text = ""
        Else
            txtState.Text = drpub.State
        End If

        If drpub.IsZipNull Then
            txtZipCode.Text = ""
        Else
            txtZipCode.Text = drpub.Zip
        End If
    End Sub
Private Function IsNull(ByVal toBeCheckedObject As Object, Optional ByVal returnObject As Object = Nothing) As Object
    Try
        If toBeCheckedObject Is DBNull.Value Then
            Return returnObject
        ElseIf toBeCheckedObject Is Nothing Then
            Return returnObject
        Else
            Return toBeCheckedObject
        End If
    Catch ex As Exception
        Throw ex
    End Try
End Function

Then use the function to check the data...

If Not String.IsNullOrEmpty(Cstr(IsNull(drpub("Name"), String.Empty))) Then
    txtPublisher.Text = Cstr(IsNull(drpub("Name"), String.Empty))
End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.