clockwork3orange
Member
- Joined
- Oct 20, 2006
- Messages
- 21
- Programming Experience
- Beginner
All I am trying to do here is make a connection to an access database to retrieve a few records and populate a list box. Below you will see the code I am using. When I run the program and hit connect it says the connection is still open and cannot be closed. Then it jumps to this statement [FONT="]RecordCount = MyDataAdapter.Fill(MyDataSet, "user")[/FONT] and says there is an error in the FROM clause. Any idea what is wrong?
VB.NET:
Imports System.Data
Imports System.Data.OleDb
Public Class frmDBRead
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
Dim sqlString As SqlTypes.SqlString
sqlString = "SELECT * FROM user;"
Dim MyCon As OleDb.OleDbConnection
MyCon = New OleDbConnection()
MyCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\UNH\CS 623\projects\ASAP.mdb"
MyCon.Open()
Try
MyCon.Open()
Catch OleDbEXceptionerr As OleDbException
MessageBox.Show(OleDbEXceptionerr.Message, "Access SQL")
Catch invalidoperationexeceptionerr As InvalidOperationException
MessageBox.Show(invalidoperationexeceptionerr.Message, "Access SQL")
End Try
Dim MyDataAdapter As OleDb.OleDbDataAdapter
MyDataAdapter = New OleDbDataAdapter(sqlString, MyCon)
Dim MyDataSet As DataSet
MyDataSet = New DataSet()
Dim RecordCount As Integer
RecordCount = MyDataAdapter.Fill(MyDataSet, "user")
Dim N As Integer
Try
For N = 0 To RecordCount - 1
lstDBRead.Items.Add(MyDataSet.Tables("user").Rows(N).Item("userLastName"))
Next N
Catch ex As Exception
MessageBox.Show("Error - " & ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class