[VB.Net] Trouble with ABO.net connections.

I am simple trying to populate listboxes using the OleDbDataReader.

I keep getting this exceptional error saying ExecuteReader requires an open and available Connection. The connection's current state is closed.

I am doing something wrong with the connection. Thank you for taking a look at my problem.

This is what I have so far

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Form2.Show()
    Form3.Show()
    Dim connString As String
    Dim myConnection1 = New OleDbConnection()
    connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Survey.mdb"
    myConnection1.ConnectionString = connString
    myConnection1.Open()

    Dim myCommand As New OleDbCommand("SELECT * FROM Survey")
    myCommand.Connection = myConnection1

    Dim myReader As OleDbDataReader
    myReader = myCommand.ExecuteReader       

    While myReader.Read()
        ListBox2.Text = (myReader("Survery_id"))
        ListBox3.Text = (myReader("Surveryname"))
    End While

End Sub

End Class

tl;dr - I can't get the conneciton to work for the DoleDbData Reader

Posted Dec 2, 2012, 4:54 PM UTC · edited

43
Loading comments…