Results 1 to 3 of 3

Thread: Query works in Access 2k but not in VB6

  1. #1
    Guest
    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:

    Code:
    ID    Name              Notes
    1     Matthew Ralston
    If I run the following query
    Code:
    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:

    Code:
    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]

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    ADO vs DAO

    ADO uses
    Code:
    SELECT ID, Name FROM People WHERE Name LIKE 'm%'
    and DAO uses
    Code:
    SELECT ID, Name FROM People WHERE Name LIKE 'm*'
    See the diffrence, % for ADO and * for DAO
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  3. #3
    Guest
    Ooooh!!!!! My hero!!!! Thank you! Thank you! Thank you!


    Geez how idiotic is that?
    Am gonna shoot Bill G when I see him next!!!


    Well...at least it works now! Ta. It was drivin me up the wall.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width