Results 1 to 7 of 7

Thread: How to using like operator and wildcard with Mysql ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2011
    Posts
    151

    How to using like operator and wildcard with Mysql ?

    Hello everyone,
    good day,

    i use this code to search in access database and work good

    Code:
    RS.Open "select * from Table1 where Name and Code like '" & Trim(Text1.Text) & "%'", DB, adOpenStatic, adLockOptimistic
    
    Do Until RS.EOF
        Grid1.AddItem RS!Paccode & vbTab & RS!Name
        RS.MoveNext
    Loop
    but if i use this code with mysql database don't show the data, i can't search more than one fields

    so when code only like this work fine with Mysql database

    Code:
    RS.Open "select * from Table1 where Name like '" & Trim(Text1.Text) & "%'", DB, adOpenStatic, adLockOptimistic
    how i using like operator and wildcard together ?

    waiting for help

    Best Regards

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: How to using like operator and wildcard with Mysql ?

    SQL isn't like English... it doesn't understand what you mean by "where Name and Code Like...." so you have to be specific ....
    "where Name like 'something%' and Code like 'Something%' "

    Yes... that means if you want to more than two fields, you have to do that for each and every field...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2011
    Posts
    151

    Re: How to using like operator and wildcard with Mysql ?

    Thank you for your replay

    i try to edit the code to be specific but not working and show error

    i need to search in mysql when i typing in Textbox like make filter data

    waiting for help

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,531

    Re: How to using like operator and wildcard with Mysql ?

    well, unfortunately my crystal ball is in the shop being fixed, and I'm not sitting in your lap, so I don't see what you're seeing, so I have no idea what error you're getting.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2011
    Posts
    151

    Re: How to using like operator and wildcard with Mysql ?

    i just need help to edit this code to work with mysql and filter data when i typing in textbox

    i try to edit code but not working so could you please edit this code to work fine

    waiting for help

    Best Regards

  6. #6
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: How to using like operator and wildcard with Mysql ?

    He already showed you what you needed to do, but you still have not shown the code you supposedly modified using his recommendation. I am surprised the code you showed at the top of the first post worked in Access. Correct SQL syntax would be like TG said
    Code:
    SELECT * FROM Table1 WHERE Name LIKE 'somepartialstring%' AND Code LIKE 'anotherpartialstring%';
    This works perfectly fine in MySQL 5.6.35.

  7. #7
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    Re: How to using like operator and wildcard with Mysql ?

    Quote Originally Posted by topshot
    I am surprised the code you showed at the top of the first post worked in Access.
    yes,it works in MSaccess, provided you tell MSaccess to use SQL-92
    (SQL-92 is an option since MSaccess 2003, if i remember correctly)
    but i am almost 100% sure it will not return what vbgedo thinks it will return
    vbgedo, try leaving the Name field blank in a few records
    do not put off till tomorrow what you can put off forever

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