Question object reference error

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
I have a dataset in the mainform

VB.NET:
    Dim ds As DataSet
    Public Property dsValue() As DataSet
        Get
            Return ds
        End Get
        Set(ByVal value As DataSet)
            ds = value
            btSave.Enabled = True
        End Set
    End Property
and i am trying to add a table to it from another form.
VB.NET:
Dim newTable As DataTable
newTable = New DataTable("Name")
'codes to fill the table
But it sometime give an "object reference is not set to an instance of an object" error when i add the table.
VB.NET:
    Delegate Sub updateDSCallback()
    Private Sub updateDS()
        Try
            If Me.InvokeRequired Then
                Dim d As New updateDSCallback(AddressOf updateDS)
                Me.Invoke(d, New Object() {})
            Else
                formMain.dsValue.Tables.Add(newTable)    'error here
                formMain.loadTree()
                Me.Close()
            End If
        Catch ex As Exception
        End Try
    End Sub
Used to work fine but now i dont know why it start to give that error. it seem to work half the time and error half the time.
 
Last edited:
What changed in your program or environment between the time it worked consistently and the time it started giving you problems?

Code does not work one day and not work the next without something specific happening.
 
I call updateDS the same way over and over with the same table. the thing that puzzles me is it works half the time and fail half the time.
 
I think it was cause i changed the form to fixdialog and added to the button that start the backgroundworker that fills the table.

VB.NET:
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
it works everytime now after i removed it. i guess it closed the form before the updateds was invoked half the time and the other half it got there before it was closed
 
Back
Top