Update from datatable

Stoffel

Member
Joined
Dec 11, 2004
Messages
16
Location
Belgium
Programming Experience
1-3
Hiya,

I want to update from a datatable I have,
but when I use the code below, I will get an error

Object reference not set to an instance of an object

Anyone has an idea?

This I use for loading the data
VB.NET:
  Public Sub New()
    Dim i As Integer
    Try
      categorie = New bsCategorie

      Dim cm As New OleDbCommand("SELECT * FROM tblCategorie ORDER BY Naam", cnKookboek)
      da = New OleDbDataAdapter(cm)

      If Not IsNothing(tblCategorie) Then
        tblCategorie.Clear()
      End If

      tblCategorieAantal = da.Fill(tblCategorie)

    Catch ex As Exception
      Throw New System.Exception("dbCategorie - Sub new" & vbCrLf & ex.Message)
    End Try
  End Sub

And this I use for updating it
VB.NET:
  Public Sub Wijzig(ByVal nCategorie As bsCategorie, ByVal pos As Integer)
    Try
      tblCategorie.Rows(pos).Item("Naam") = nCategorie.Naam

      [b]da.Update(tblCategorie)[/b] 'The error occurs here
      tblCategorie.Clear()
      da.Fill(tblCategorie)

    Catch ex As Exception
      tblCategorie.Clear()
      da.Fill(tblCategorie)
      Throw New System.Exception("dbBegunstigden - Sub Wijzig" & vbCrLf & ex.Message & vbCrLf & Err.Description)
    End Try
  End Sub
 
The above error usually appears if you have not initialized an object. Check your data adapter, see if has been initialized.
 
It is initialized
I declared it as a global parameter for that class
VB.NET:
Private da As OleDbDataAdapter

And it works fine in the Sub New, but won't work in Sub Wijzig

Even when I declare a new OleDbDataAdapter in Sub Wijzig, it still won't work

Any ideas?
 
Back
Top