Question "object reference not set to an instance of an object" error when update MS Access

phoebe_ccy

Member
Joined
Oct 12, 2009
Messages
6
Programming Experience
Beginner
"object reference not set to an instance of an object" error when update MS Access

Hi, I have this program in VB.NET and I am trying to insert/update/delete into MS Access. But I hit this error "System.NullReferenceException: object reference not set to an instance of an object".

The weird thing is, sometimes it works, and sometimes it hit error. The program is calling the same function each time, but why this strange thing happens?

***** Declaration ********
Public OleDbConnection As System.Data.OleDb.OleDbConnection


***** Delete Function *******
Public Sub DELETE_DETAILS()

Dim OleDbDeleteCommand As System.Data.OleDb.OleDbCommand
OleDbDeleteCommand = New System.Data.OleDb.OleDbCommand

Try
OleDbDeleteCommand.CommandText = "DELETE FROM TABLE1"

OleDbDeleteCommand.Connection = OleDbConnection

OleDbDataAdapter.DeleteCommand = OleDbDeleteCommand

OleDbDataAdapter.DeleteCommand.ExecuteNonQuery()

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
ERR_FLG = "ERR"
End Try

End Sub
 
Back
Top