G
Guest
Im trying to connect to an Access database using a class. I think I have been
able to establish the connection but when trying to test it by pulling data
from the database im getting the error:
"An unhandled exception of type 'System.NullReferenceException' occurred in
DB.exe
Additional information: Object reference not set to an instance of an object."
The code that I currently have is:
----------------------
Public Class DB
Private myConnection As New OleDb.OleDbConnection
Private myDataAdapter As New OleDb.OleDbDataAdapter
Private dsPeople As Data.DataSet
Private tblPeople As Data.DataTable
Private intPosition As Integer = 0
Sub New(ByVal Path As String)
Dim strSelect As String
Try
myConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & ";Persist Security
Info=False"
myConnection.Open()
strSelect = ("SELECT FirstName, LastName, HomePhone, WorkPhone,
CellPhone, Email, MailingAddress, City, State, Zip, Comment, ID FROM People")
myDataAdapter = New OleDb.OleDbDataAdapter(strSelect,
myConnection)
Dim intSize As Integer
dsPeople = New DataSet
intSize = myDataAdapter.Fill(dsPeople)
tblPeople = dsPeople.Tables(0)
Catch ex As Exception
End Try
End Sub
Public Sub Assign()
FirstName = dsPeople.Tables(0).Rows(intPosition).Item(0).tostring
'(Problem Line)
End Sub
Property FirstName() As String
Get
Return FirstName
End Get
Set(ByVal Value As String)
FirstName = "bob"
End Set
End Property
End Class
---------------------
When I instanciate the object I get the message on the line indicated.
This has me stumped as I'm sure it's a simple problem.
Thanks for any help
Mole
able to establish the connection but when trying to test it by pulling data
from the database im getting the error:
"An unhandled exception of type 'System.NullReferenceException' occurred in
DB.exe
Additional information: Object reference not set to an instance of an object."
The code that I currently have is:
----------------------
Public Class DB
Private myConnection As New OleDb.OleDbConnection
Private myDataAdapter As New OleDb.OleDbDataAdapter
Private dsPeople As Data.DataSet
Private tblPeople As Data.DataTable
Private intPosition As Integer = 0
Sub New(ByVal Path As String)
Dim strSelect As String
Try
myConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path & ";Persist Security
Info=False"
myConnection.Open()
strSelect = ("SELECT FirstName, LastName, HomePhone, WorkPhone,
CellPhone, Email, MailingAddress, City, State, Zip, Comment, ID FROM People")
myDataAdapter = New OleDb.OleDbDataAdapter(strSelect,
myConnection)
Dim intSize As Integer
dsPeople = New DataSet
intSize = myDataAdapter.Fill(dsPeople)
tblPeople = dsPeople.Tables(0)
Catch ex As Exception
End Try
End Sub
Public Sub Assign()
FirstName = dsPeople.Tables(0).Rows(intPosition).Item(0).tostring
'(Problem Line)
End Sub
Property FirstName() As String
Get
Return FirstName
End Get
Set(ByVal Value As String)
FirstName = "bob"
End Set
End Property
End Class
---------------------
When I instanciate the object I get the message on the line indicated.
This has me stumped as I'm sure it's a simple problem.
Thanks for any help
Mole