VB.NET error when using MS Access

Talk2Tom11

Well-known member
Joined
Feb 22, 2004
Messages
144
Location
Westchester, NY
I am writing an inventory application that uses MS access as a backend. I am having no problems accessing and obtaining information from the database through my program except in one spot. This is the code:

[VB]
Dim Pro As New OleDb.OleDbCommand
Dim Read2 As OleDb.OleDbDataReader
Dim Con3 As New OleDb.OleDbConnection
Dim ID3 As New OleDb.OleDbCommand

Private Sub CmbBoxProducts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbBoxProducts.SelectedIndexChanged
Con3.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\subdir\database.mdb;Mode=ReadWrite;Persist Security Info=False"

If txtBoxWatch.text = "Product" Then

ID3.Parameters.Add("Product", Data.OleDb.OleDbType.Variant)
ID3.Parameters("Product").Value = CmbBoxProducts.Text

Con3.Open()

Read = ID3.ExecuteReader()

With Read
While .Read
txtBoxAmount.Items.Add(.GetValue(1))
End While
End With

Con3.Close()
End If
End Sub[/VB]


The error i am receiving is:

ExecuteReader: Connection property has not been initialized.
 
You need to set the commands connection to be your active connection. Something like
Code:
ID3.Connection = Con3
should do the trick.
 
Back
Top