bad sql command?

archer_coal

Well-known member
Joined
Apr 4, 2003
Messages
96
whats wrong with this code? It halts at
Dim objDataReader As OleDbDataReader = dbCmd.ExecuteReader so i assume there is a problem with the dbCmd syntax but i dont see what it might be.

with this error : An unhandled exception of type System.Data.OleDb.OleDbException occurred in system.data.dll


Make the connection
Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\data\20304aa1.mdb")

dbConn.Open()


Dim dbCmd As New OleDbCommand("SELECT * FROM April ORDER BY id", dbConn)
Dim objDataReader As OleDbDataReader = dbCmd.ExecuteReader

Try
objDataReader.Read()


lbx1.Items.Clear()

Do While objDataReader.Read

lbx1.Items.Add(objDataReader("id"))

Loop
objDataReader.Close()

Catch
End Try
 
Code:
Try
Dim dbConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\data\20304aa1.mdb")
dbConn.Open()

Dim dbCmd As New OleDbCommand("SELECT * FROM April ORDER BY id", dbConn)
Dim objDataReader As OleDbDataReader = dbCmd.ExecuteReader()

While objDataReader.Read
       lbx1.Items.Add(objDataReader("id"))
Wend
objDataReader.Close()
Catch
       Msgbox(err.description)
End Try

What does the message box say code looks ok apart from using the .read command out of the while
 
Ok

It was a bad database. I had several problems with accessing data from that db so i built a new one and ran the code. It works fine now.
Thanks for your help
 
Back
Top