I am working in vb6 and am new to database access. I can't seem to figure out the syntax for the following:
rs1.Open "select * from orders where category = '" & button & " and invoice = " & invoice & "' order by guest", db, adOpenStatic, adLockOptimistic
The above statement doesn't work. What am I doing wrong?
JerrybYour embedded quotes were misplaced. The SQL being run is like:
select * from orders where category = 'xxx and invoice = yyy ' order by guest
But you probably meant this:
select * from orders where category = 'xxx' and invoice = 'yyy' order by guest
Try this:
rs1.Open "select * from orders where category = '" & button & "' and invoice = '" & invoice & "' order by guest", db, adOpenStatic, adLockOptimistic
(This is assuming that both button and invoice are strings rather than numbers - for numbers, you don't need the quotes.)
Hint: it's a good idea to print the SQL that is failing to see if it makes sense - e.g.:
Response.Write "select * from orders where category = '" & button & " and invoice = " & invoice & "' order by guest"
No comments:
Post a Comment