Results 1 to 8 of 8

Thread: How do I make wildcards work in sql thru ado?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    51

    How do I make wildcards work in sql thru ado?

    I've got a tricky problem, I can't fix it in msdn, so what to do? time to come to you gurus here at vbforums

    The situation is I'm accessing an access 2000 (jet) database from vb6 using ADO. when i try and open a recordset based on this string:

    SELECT Files.[FileID], Files.[File Name], CDs.[CDID], CDs.[CD Name] FROM CDs INNER JOIN Files ON CDs.CDID = Files.CDID WHERE ((Files.[File Name]) Like 'gladiato*');

    it returns 0 records. If I run the same string directly in an Access query it works fine and i get 1 record 'gladiator'. also if i change the 'gladiato*' to 'gladiator' then it works thru vb.

    It seems to me that i can't use wildcards in the sql string from vb. does anyone know if this is correct, and if it is, does anyone know a way around it? my program sort of revolves around this working, it's a searching program
    Last edited by Herbatic; Aug 8th, 2002 at 02:27 AM.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    use % not *

    Code:
    SELECT Files.[FileID], Files.[File Name], CDs.[CDID], CDs.[CD Name] FROM CDs INNER JOIN Files ON CDs.CDID = Files.CDID WHERE ((Files.[File Name]) Like 'gladiato%');
    -= a peet post =-

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    51
    OK, while i was writing my last post i finally realised that the wildcards were the problem. So, stupidly, I searched vbforums for sql wildcards after hitting the submit button. and promptly found out that ado uses % instead of *, and _ instead of ?. So problem solved, sorry to have bothered everyone with such an easy question.

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    51
    OK. That makes a new problem. I am searching file names in my database, and filenames can have % or _ in them so what is the override-type thing in ado so that it will search for a % or _ instead of treating them as wildcards?

  6. #6
    Fanatic Member
    Join Date
    Nov 2001
    Location
    Bangkok
    Posts
    969

    Hi

    I am not sure but maybe %% and __ instead?

    Franky

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    No, I think you have to use brackets around the wildcard symbols if you want to search for them.

    SELECT * FROM FileTable WHERE FileName LIKE '2002[%]04[_]%'

    will give you files with the following mask

    2002%04_ABC.DOC
    2002%04_DEF.DOC
    2002%04_TEST.DOC
    .
    .
    .
    -= a peet post =-

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2001
    Posts
    51
    Thanks All
    peet - you were right the [ ] do the trick

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