CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2008
    Posts
    43

    cannot use * in ado record sets

    I have a program that looks up data in an access database using an ado recordset in visual studio 2005. my problem is that i wanted to be able to enter something into a text box and select only records that CONTAIN what ever is in the text box. i've tried the following:

    "select * from myQuery where (field like *'" & textBox.text & "'*);"

    which works with an access query but when i've used the exact same statement in a recordset.open command it doesn't find any records. does anyone know why this is happening or another way of searching records?

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: cannot use * in ado record sets

    Been ages since I've messed around with access, but shouldn't the ' be on the other side of the *?

    Like this:
    Code:
    "select * from myQuery where (field like '*" & textBox.text & "*');"

  3. #3
    Join Date
    Apr 2007
    Posts
    81

    Re: cannot use * in ado record sets

    johntheface,

    In addition to Alsvha's comment, I thought ADO's wildcard character was %, not *.

    Kerry Moorman

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: cannot use * in ado record sets

    Quote Originally Posted by kmoorman
    johntheface,

    In addition to Alsvha's comment, I thought ADO's wildcard character was %, not *.

    Kerry Moorman
    For MS-Access databases % sign does not work. You will have to use * as shown in Post # 2.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: cannot use * in ado record sets

    this is correct:

    Code:
    "select * from myQuery where field like '" & textBox.text & "*'"
    no * before the like field, but afterwords. For phone numbers, I've found that we had to use % before. YMMV
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: cannot use * in ado record sets

    Quote Originally Posted by Shuja Ali
    For MS-Access databases % sign does not work. You will have to use * as shown in Post # 2.
    Not sure I understand or agree ( although I'm not a boffin on databases )
    In a recent project, using MS Access, I had to use the % indicating the remaining characters.

    I did this :
    Code:
           PlaySearch = "SELECT * FROM " & pclListPT.PCLRetStr '& " WHERE " & _
                PlayFieldStr & " LIKE '" & abPConditions.Text & "%' "
    When I entered a value such as Met in the abPConditions TextBox, it returned all values starting with Met. So, If I used the Artist field ( pclListPT.PCLRetStr ) , it returns me all Metallica records.

    It works for me
    Last edited by HanneSThEGreaT; June 7th, 2008 at 05:15 AM.

  7. #7
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: cannot use * in ado record sets

    Quote Originally Posted by HanneSThEGreaT
    Not sure I understand or agree ( although I'm not a boffin on databases )
    In a recent project, using MS Access, I had to use the % indicating the remaining characters.
    I stand corrected.

    I have not touched MS-Access since past 4 years now. I remember using * as a wild card, but that might have changed now.

  8. #8
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: cannot use * in ado record sets

    As I recall, you use % in ADO(.NET) queroes, but * within Access (as a front end to Jet) for wildcard
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  9. #9
    Join Date
    Jan 2008
    Posts
    32

    Re: cannot use * in ado record sets

    If you prepare a query in MS Access you must use * char..
    but if you connect database with Ado, you must use % char...

    I have used % char in many projects..

  10. #10
    Join Date
    Apr 2008
    Posts
    43

    Re: cannot use * in ado record sets

    thanks guys, it's %

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

Featured