943,515 Members | Top Members by Rank

Ad:
Sep 24th, 2008
0

How to using "like" in VB6

Expand Post »
Hi all.
I have error with script below :

Dim sql as string
sql = "select * from [table] where [field] like '%" & text1.text & "%'"

how must I write "%" after "like"?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
murnibta is offline Offline
1 posts
since Sep 2008
Sep 24th, 2008
0

Re: How to using "like" in VB6

What is the error message you get? SQL seems ok to me.

%-character is used for pattern matching and it matches any number of characters:

sql = "select * from [table] where [field] like 'VB%'"
matches [field] starting with "VB" (like "VB6 Language"),

sql = "select * from [table] where [field] like '%VB'"
matches [field] ending with "VB" (like "Microsoft's VB"), and

sql = "select * from [table] where [field] like '%VB%'"
matches [field] containing "VB" ("My VB6 Tutorial")
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Sep 24th, 2008
0

Re: How to using "like" in VB6

For MS Access, use * (asteriks) instead of %

"Select * from <table> where <field> like '" & text1.text & "*'"

For other databases, it will depend on the database. Oracle uses "%" (IIRC, not 100% sure) and SQL Server uses a different character.
Reputation Points: 20
Solved Threads: 10
Junior Poster
aparnesh is offline Offline
193 posts
since Jul 2005
Sep 25th, 2008
0

Re: How to using "like" in VB6

Quote ...
For MS Access, use * (asteriks) instead of %
is correct in Access. However, when you use SQL in VB you use %-character. This is with ADO, in DAO you may had to use *-character, don't remember for sure anymore.
Reputation Points: 218
Solved Threads: 201
Veteran Poster
Teme64 is offline Offline
1,024 posts
since Aug 2008
Jan 30th, 2011
-1
Re: How to using "like" in VB6
replace % with * for ms-access
Reputation Points: 10
Solved Threads: 0
Newbie Poster
alamnaryab is offline Offline
1 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: VB Add/Edit/Save Pictures in Access DB
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: monthly report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC