How to using "like" in VB6

Reply

Join Date: Sep 2008
Posts: 1
Reputation: murnibta is an unknown quantity at this point 
Solved Threads: 0
murnibta murnibta is offline Offline
Newbie Poster

How to using "like" in VB6

 
0
  #1
Sep 24th, 2008
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"?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: How to using "like" in VB6

 
0
  #2
Sep 24th, 2008
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")
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 186
Reputation: aparnesh is an unknown quantity at this point 
Solved Threads: 10
aparnesh's Avatar
aparnesh aparnesh is offline Offline
Junior Poster

Re: How to using "like" in VB6

 
0
  #3
Sep 24th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: How to using "like" in VB6

 
0
  #4
Sep 25th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC