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 » 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:35 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.
Yet, 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 03:56 PM    Post subject: Reply with quote

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

Denis Marchand
Back to top
View user's profile Send private message
blackhd
Newbie


Joined: 23 Jul 2005
Posts: 5

PostPosted: Jul 23rd, 2005 01:08 PM    Post subject: Reply with quote

ya just abt to tell you to replace the * with %
Back to top
View user's profile Send private message
Denis Marchand
Newbie


Joined: 15 Jul 2005
Posts: 6

PostPosted: Jul 24th, 2005 02:22 AM    Post subject: Reply with quote

OK, thanks!

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 » 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