PDA

View Full Version : access database queries


sweenster
02-09-2005, 03:01 PM
I'm using an access database and am running the following query on it:

objCommand.CommandText = "SELECT * FROM Team WHERE Car='A' ORDER BY Name"

but i want to modify this so I can select two different parameters. I have tried:

objCommand.CommandText = "SELECT * FROM Team WHERE Car='A' AND Position='Engine' ORDER BY Name"
but this doesnt seem to work. I've also tried & and && as well intstead of AND but all have failed. Any suggestions?

TennesseeGuy
02-09-2005, 03:20 PM
enclose each and statement in ()
i.e. (Car='A') AND (Position='Engine')

ghell
02-09-2005, 04:38 PM
thats weird, it really should work
try looking at http://www.w3schools.com/sql/sql_and_or.asp

i tried objConn.Execute("SELECT * FROM table WHERE field1 = '1' AND field2 = '2'") and it worked :confused:

miranda
02-10-2005, 08:47 AM
are you working in asp.net if so are these hardcoded select statements or are they actually using variables instead? if that is the case did you pass the strings into your function call?

if not working in asp.net if these are variables then you need to include ampersands like so

WHERE car = "' & A & "' AND position = '" & engine & "'"

Also if this is a variabel and A is an integer then there is no single quote around it it is done like this

WHERE car = " & A & " AND position = '" & engine & "'"