Problem with LIKE

Posted on 2006-04-13
Last Modified: 2010-04-05
I'm using delphi7 connecting to MS Access2000 database using ADO.
I try to use (LIKE) in SELECT statement it's give nothing, but if I put this statement in access query it's work properly.
The statement like this:
ADO_Name.SQL.Text :=  'SELECT * FROM TableName'+
                                     ' where TableName.FieldName like '''+'*'+TextBoxName.Text+'*'+''' order by'+
                                     ' TableName.FieldName ';

This statement is work properly without (LIKE).

Question by:abafadel
    LVL 14

    Accepted Solution


    ADO_Name.SQL.Text :=  'SELECT * FROM TableName'+
                                         ' where TableName.FieldName like '''+'%'+TextBoxName.Text+'%'+''' order by'+
                                         ' TableName.FieldName ';

    LVL 6

    Expert Comment

    Hello sir,

      It is not *, replace it with % and give the query as follows

    ADO_Name.SQL.Text :=  'SELECT * FROM TableName'+
                                         ' where TableName.FieldName LIKE ''%' + Trim(TextBoxName.Text) + '%'' ORDER BY +
                                         ' TableName.FieldName ';
    with regards,
    LVL 12

    Expert Comment

    FieldName is some string type I hope, not DATE or TIME ?
    LVL 5

    Expert Comment


    Pierre C is correct as is saravananvq.

    Access uses DAO which uses '*' for the wild card ADO uses '%'.

    You might wonder why Microsoft are still using DAO - its 5 times faster is why......


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now