By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 IT Pros & Developers. It's quick & easy.

how does LIKE operator work?

P: 24
I want to write sql sentence with LIKE operator. I wrote this code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2. List1.Clear
  3. Set db = OpenDatabase("the path of my database")
  4. Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.pavarde LIKE '%Pet%';")
  5. While Not rec.EOF
  6. List1.AddItem rec!ID & "  " & rec!Vardas & "   " & rec!pavarde & "  " & rec!Data
  7. rec.MoveNext
  8. Wend
  9. rec.Close
  10. db.Close
  11. End Sub
and my program does nothing. I don't undestand how does LIKE work?
Apr 29 '07 #1
Share this Question
Share on Google+
3 Replies


markmcgookin
Expert 100+
P: 648
I want to write sql sentence with LIKE operator. I wrote this code:

Private Sub Command8_Click()
List1.Clear
Set db = OpenDatabase("the path of my database")
Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.pavarde LIKE '%Pet%';")
While Not rec.EOF
List1.AddItem rec!ID & " " & rec!Vardas & " " & rec!pavarde & " " & rec!Data
rec.MoveNext
Wend
rec.Close
db.Close
End Sub

and my program does nothing. I don't undestand how does LIKE work?

Hi,

I developed a VB app in the compact framework for a PDA and using SQL Sever CE and not MS access, but when I was doing something like this, I used this format:

I am assuming that you have assigned "Pet" as a string variable or something

i.e.
Expand|Select|Wrap|Line Numbers
  1. Dim Pet As String
  2. Pet = "Dog"
  3.  
  4. etc...
  5.  
  6. Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.pavarde LIKE ' " & Pet & " ' ")
  7.  
But I am not sure if that would be the same for an Access DB
Apr 29 '07 #2

P: 24
I didn't assign Pet as a variable because I think that it is only a string line I want to find in my database. Why need I to assign Pet as a variable? When I wrote this code in Access I wrote:

Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.pavarde LIKE "*Pet*"; ")

and the querry was good, but with visual basic it doesn't work. I don't understand why?
Apr 29 '07 #3

Expert 5K+
P: 8,434
I didn't assign Pet as a variable because I think that it is only a string line I want to find in my database. Why need I to assign Pet as a variable? When I wrote this code in Access I wrote:

Set rec = db.OpenRecordset("SELECT * From asmenu_info WHERE asmenu_info.pavarde LIKE "*Pet*"; ")

and the querry was good, but with visual basic it doesn't work. I don't understand why?
Actually, I think you have the Like clause correct. It should work exactly the same from VB as when used directly in Access. However, I note that in your original post you have converted the asterisks to percent symbols. If you are still talking to an Access database, I believe you still need to use the asterisks.
Apr 29 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.