Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Search for partial strings in database

I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.

Example:
strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
when opened with a recordset
rsMember.Open strSQL, etc.
returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.

If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.

Thanks

Comments

  • infidelinfidel Member Posts: 2,900
    : I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.
    :
    : Example:
    : strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
    : when opened with a recordset
    : rsMember.Open strSQL, etc.
    : returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.
    :
    : If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.

    In standard SQL, the LIKE wildcard is '%', not '*'.
  • ksparksksparks Member Posts: 15
    : : I'm trying to do a search for a partial string in an Access database using an ADODB recordset in VB 6. However, whenever I do a SQL statement from VB that uses LIKE and an *(to represent any character) no recordset is found.
    : :
    : : Example:
    : : strSQL = "SELECT * FROM Table WHERE Name Like 'M*'"
    : : when opened with a recordset
    : : rsMember.Open strSQL, etc.
    : : returns nothing, even though, if I were to put this exact SQL statement into a query in MS Access, it would return several records.
    : :
    : : If someone could tell me what I am doing wrong and how to correct this problem, I would really appreciate it.
    :
    : In standard SQL, the LIKE wildcard is '%', not '*'.
    :

    Thank you, the % sign worked. I used the * because that is the wildcard for Access. Didn't think to try the % sign.
  • Andre YoungAndre Young USAMember Posts: 0

    < http://forcoder.org /> free video tutorials and ebooks about \ Delphi, Visual Basic, Swift, JavaScript, Scratch, Objective-C, PHP, Ruby, Go, MATLAB, C++, Perl, R, Python, C, Java, C#, PL/SQL, Assembly, Visual Basic .NET Awk, Rust, Scheme, Apex, Dart, ABAP, VBScript, F#, ML, Scala, Alice, Lua, Julia, FoxPro, Logo, Transact-SQL, Fortran, Hack, D, Erlang, Ada, Bash, Kotlin, COBOL, Lisp, Crystal, LabVIEW, Prolog, SAS, Clojure \ ___________

Sign In or Register to comment.