Hello everyone,
Please bear with me. I have not programmed in Visual Basic since 1994. And
now my employer has given me the tedious task of writing a database driven
program.
I have a access database with 5 tables, the perticular one I am interested
in is named CUSTOMERS.
Here is a section of my code:
Inherits System.Windows.Forms.Form
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dbpath As String
Dim dbConn As OleDbConnection
Dim dbCommand As OleDbCommand
OpenFileDialog1.ShowDialog()
dbPath = OpenFileDialog1.FileName
Debug.Write(dbPath)
dbConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
& "DATA SOURCE=" _
& dbpath)
dbCommand.CommandText = "SELECT * FROM CUSTOMERS"
dbCommand.Connection = dbConn
dbConn.Open()
Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader
While dbDR.Read
txtCustCode = dbDR("CUSCODE".ToString)
End While
End Sub
However when I run this program, I get the following error message:
An unhandled exception of type 'System.NullReferenceException' occurred in
WindowsApplication1.exe
Additional information: Object reference not set to an instance of an
object.
Could someone please be so kind as to point out where I am going wrong?
Thanks