Solved

wildcard * don't work with sql query to mdb using ado

Posted on 2004-10-14
6
298 Views
Last Modified: 2008-03-06
Hi, experts
 my code is
        cnDBF.Provider = "Microsoft.Jet.OLEDB.4.0"
       ' cnDBF.Properties("Extended Properties") = "dBase iv" commented now use .mdb
        cnDBF.Properties("Data Source") = Text1.Text
        cnDBF.CursorLocation = adUseClient
        cnDBF.Open
 
        sSQL = "SELECT * " & _
            "FROM kladr where mcode like '*000000';"
         Set rsRegion = New adodb.Recordset
        rsRegion.Open sSQL, cnDBF, adOpenDynamic, _
                       adLockBatchOptimistic, adCmdText

mcode is a string field and nothing records is selected, but the other wildcard
work true :
        sSQL = "SELECT * " & _
         "FROM kladr where code like '#####00000000';"
Can anybody help me/  

0
Comment
Question by:Eugeny
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
Z03niE earned 250 total points
ID: 12316456
My friend, use percent symbol(%) instead of wildcard.
Something like :

        sSQL = "SELECT * " & _
            "FROM kladr where mcode like '%000000';"
0
 
LVL 10

Expert Comment

by:anv
ID: 12317085
hi  Eugeny

actually  will work for SQL Server  Databases and % works for MS Access Databases...

so instead of * use %

as commented by Z03niE
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12318178
anv, are you sure?

(taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_la-lz_115x.asp)
%  -  Any string of zero or more characters. WHERE title LIKE '%computer%' finds all book titles with the word
        'computer' anywhere in the book title.

_   -  Any single character. WHERE au_fname LIKE '_ean' finds all four-letter first names that end with ean (Dean,
        Sean, and so on).

[ ]  - Any single character within the specified range ([a-f]) or set ([abcdef]). WHERE au_lname LIKE '[C-P]arsen'
        finds author last names ending with arsen and beginning with any single character between C and P, for
        example Carsen, Larsen, Karsen, and so on.

[^] - Any single character not within the specified range ([^a-f]) or set ([^abcdef]). WHERE au_lname
        LIKE 'de[^l]%' all author last names beginning with de and where the following letter is not l.

I was under the impression that, as Z03niE said, Eugeny should use '%'.

J
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12318191
anv:

My apologies; you did actually say to use '%'.

J.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

17 Experts available now in Live!

Get 1:1 Help Now