473,425 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

VB.NET 2003 Database Access Issues

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
Nov 23 '05 #1
3 1530

"Materialised" <ma**********@privacy.net> wrote in message
news:3t************@individual.net...
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

I'll make a wild guess, as you don't mention which line throws the
exception.
Is the exception thrown in the first line where you reference dbCommand,
perhaps this one?

dbCommand.CommandText = "SELECT * FROM CUSTOMERS"

Where you do create an OleDbConnection object with:

dbConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
& "DATA SOURCE=" _
& dbpath)

You never create an OleDbCommand object.

Nov 23 '05 #2
Here's a version that would show you the line # in the stack trace:

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As EventArgs) Handles MyBase.Load
Try
Dim dbpath As String = "c:\t\db1.mdb"
Dim dbConn As New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbpath)
dbConn.Open()
Dim dbCommand As New OleDbCommand( _
"SELECT * FROM Customers", dbConn)
Dim dbDR As OleDb.OleDbDataReader = dbCommand.ExecuteReader
Do While dbDR.Read
ComboBox1.Items.Add(dbDR("CUSCODE"))
Loop
Catch ex As Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace, "Error")
End Try
End Sub

Nov 23 '05 #3
Try
Dim dbCommand As New OleDbCommand
--
Dennis in Houston
"Materialised" wrote:
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

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
3
by: Colin Chudyk | last post by:
Hi, Here is my situation. Can anyone provide insight? I have developed a database in Access 2002. I am planning to distribute it as a split MDE (front) / MDB (back) to be used by the Access...
2
by: Jennifer B. | last post by:
Hi Every Body: I hope this is to the right post. I apologize if I am incorrect. Could anyone please answer one or any of the following questions for Access 2003: - Maximum size of an...
11
by: John Ortt | last post by:
Hi All, Our company is migrating from Windows NT to XP and in the process from Access 97 to Access 2003. Due to the phased rollout we are faced with a situation where some users are still on NT...
2
by: lambej12 | last post by:
I am a relatively new user. My position is to maintain an Access DB that is running in a multi user enviornment and split on a network running Front(2K and 97) and BE(97). The DB has been used...
3
by: RayPower | last post by:
I'm having a system using Access 2000 as both front-end (queries, forms, reports & temp tables for reports) & back-end (data) with back-end running on the server. The application runs on the...
5
by: Ecohouse | last post by:
I'm using VB and an Access 2003. The db was originally created in Access 2000, but the computer had to have things reinstalled and now has Access 2003. So I was wondering if there are any...
14
by: jmaltese | last post by:
I need some suggestions. We had previously been running our multi-user Access 2002 applications on a Novell server. Since switching to Windows 2003 servers a few months ago, we've been having...
4
by: azjazz | last post by:
Hi - I tried to search the forums on this issue, but couldn't get good results. I'm sure this has been asked before, so hopefully it won't be too hard to find an answer ... I have a database...
3
by: NEWSGROUPS | last post by:
I am in the midst of trying to convert about 25 Access 2000 to Access 2003. The new environment consists of Office/Access 2003 and Outlook 2003. When converting the back ends I have no problems....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.