Results 1 to 5 of 5

Thread: How to use LIKE statement in the SQL Query for an ADO control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    4
    I have this ado data control and a datagrid

    The SQL Statement is something like this
    SQLString = "SELECT * FROM Main WHERE Name LIKE ('*John*')"

    when the display button is clicked, the following statements are executed,

    frmDBGrid.Adodc1.CommandType = adCmdText
    frmDBGrid.Adodc1.RecordSource = SQLString
    frmDBGrid.Adodc1.Refresh
    frmDBGrid.DataGrid1.SetFocus

    But it seems like the ado data control has no record in it, when there should be.

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb

    Your SQl should look like this:
    Code:
    SQLString = "SELECT * FROM Main WHERE Name LIKE '*John*';"
    and it will search for all record that have any character either before or after John.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    4

    Unhappy

    I've tried the following SQL statement..
    but it's still not working.
    the ado data control is greyed out. (meaning no recordset?)

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Just make sure there is a data with "John" in the Name field. If yes, then try to change the field name Name to other like MyName. Because i affraid it conflict with the system reserve word.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    4
    heh
    thanks Chris and others who have helped me out..

    btw, I can't remember who's that..
    but someone posted the solution on the forum..

    i should have change the wildcard * to %
    as in "Name LIKE ('*John*')" to "Name LIKE ('%John%')"

    think maybe it's becoz I used adodc ...
    if i've used coding instead... think * will work as well..
    coz it actually worked in the first place...

    anyway, thanks..
    btw, how do I close a thread?

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