Sep 12th, 2000, 09:46 AM
Urrrgh!!! Am soooo annoyed! OK...figure this one out if you can...
I've got an Access 2000 database called "Phone Book.mdb" in the same directory as my program.
The database contains a table called "People" with the fields "ID", "Name" and "Notes".
There is currently 1 record in the table:
ID Name Notes
1 Matthew Ralston
If I run the following query SELECT ID, Name FROM People WHERE Name LIKE 'm*' in Access it works fine and returns 1 record. However if I run it in VB using ADO 2.1 it returns 0 records:
Dim oConn As New ADODB.Connection, oRS As New ADODB.Recordset
oConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Phone Book.mdb"
oConn.Open
oRS.Open "SELECT ID, Name FROM People WHERE Name LIKE '" & "m" & "*'", oConn
oRS.MoveFirst
Debug.Print oRS("Name")
oRS.Close
oConn.Close
Note that this is a simplified version of the code...the real one runs inside a loop and puts all records returned into a treeview control. I have tested the above code and the same problem occurs.
Any ideas why?
[Edited by matthewralston on 09-12-2000 at 10:48 AM]
I've got an Access 2000 database called "Phone Book.mdb" in the same directory as my program.
The database contains a table called "People" with the fields "ID", "Name" and "Notes".
There is currently 1 record in the table:
ID Name Notes
1 Matthew Ralston
If I run the following query SELECT ID, Name FROM People WHERE Name LIKE 'm*' in Access it works fine and returns 1 record. However if I run it in VB using ADO 2.1 it returns 0 records:
Dim oConn As New ADODB.Connection, oRS As New ADODB.Recordset
oConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=Phone Book.mdb"
oConn.Open
oRS.Open "SELECT ID, Name FROM People WHERE Name LIKE '" & "m" & "*'", oConn
oRS.MoveFirst
Debug.Print oRS("Name")
oRS.Close
oConn.Close
Note that this is a simplified version of the code...the real one runs inside a loop and puts all records returned into a treeview control. I have tested the above code and the same problem occurs.
Any ideas why?
[Edited by matthewralston on 09-12-2000 at 10:48 AM]