Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Database & Reporting

Post new topic   Reply to topic
Problem with the LIKE operator
View previous topic :: View next topic  
Author Message
Denis Marchand
Newbie


Joined: 15 Jul 2005
Posts: 6

PostPosted: Jul 15th, 2005 07:10 AM    Post subject: Problem with the LIKE operator Reply with quote

Hi,
I'm trying to issue an SQL 'SELECT' statement with the 'LIKE' operator from a VB program against a .mdb database. The code is:
Dim rs As Object, SQL
SQL = "SELECT tbl_Test.Ref, tbl_Test.Name FROM tbl_Test WHERE (((tbl_Test.Name) Like 'Mar*') AND ((tbl_Test.Deleted)=False)) ORDER BY tbl_Test.Ref;"
Set rs = CreateObject("ADODB.Recordset")
rs.Open SQL, AdoContacts.ConnectionString, adOpenKeyset, adLockOptimistic '(where AdoContacts is a ADO control on my form)

This query returns an empty set while the same query issued from Access (in an Access Query) returns the correct result.
Yes, if I replace 'LIKE' with '=', then the result is OK (of course not what I want), which kinda shows that there is nothing wrong with the code and the setup (I hope). All my other SELECT statements work. Why doesn't the 'LIKE' one? Any clues?

I use VB 6.0 SP6
Many thanks in advance

Denis[/code]
Back to top
View user's profile Send private message
Denis Marchand
Newbie


Joined: 15 Jul 2005
Posts: 6

PostPosted: Jul 20th, 2005 04:00 PM    Post subject: Reply with quote

Ooops! Found the fix by myself: the SQL 'LIKE' operator requres a '%' (percent) character as a wildcard, instead of the '*' (asterisk) character I had been using.
Funny that Access accepts the asterisk as a wildcard...

Denis
Back to top
View user's profile Send private message
jmcilhinney
Freshman


Joined: 06 Jul 2005
Posts: 25
Location: Sydney, Australia

PostPosted: Jul 21st, 2005 10:37 PM    Post subject: Reply with quote

When using the Access GUI, it accepts the standard Windows widcards of "*" and "?" because it is a Windows application. SQL cares nothing about Windows though, and requires its own standard wildcards of "%" and "_".
Back to top
View user's profile Send private message
Denis Marchand
Newbie


Joined: 15 Jul 2005
Posts: 6

PostPosted: Jul 22nd, 2005 03:43 AM    Post subject: Reply with quote

Thanks! I figured it out, but I have to admit I wasted some time trying to find indirect ways like dynamically creating a view ( a query) in Access and then executing it but to no avail...
Problem solved now.
Thanks again

Denis
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » .NET Database & Reporting All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic