Can you pass a local variable into sql statement?
-
I’m trying to access one row in a table based upon its int value held locally in a variable. (I increment the 'count' variable in the application.) As you can see below, 'count' is the local variable in the application. Can this be done or is there another way? -Shannon If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if :confused:
-
I’m trying to access one row in a table based upon its int value held locally in a variable. (I increment the 'count' variable in the application.) As you can see below, 'count' is the local variable in the application. Can this be done or is there another way? -Shannon If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if :confused:
spettiford wrote: If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if Should be:
If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo **=" & count** end if
hope that helps -
spettiford wrote: If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if Should be:
If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo **=" & count** end if
hope that helpsTHANK YOU!!! I knew there was a way, but just didn't get the syntax correct. It works great and you saved me.:-D
-
I’m trying to access one row in a table based upon its int value held locally in a variable. (I increment the 'count' variable in the application.) As you can see below, 'count' is the local variable in the application. Can this be done or is there another way? -Shannon If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if :confused:
-
I’m trying to access one row in a table based upon its int value held locally in a variable. (I increment the 'count' variable in the application.) As you can see below, 'count' is the local variable in the application. Can this be done or is there another way? -Shannon If count < iResultQuery Then myConn_.CommandText = "SELECT WorkInstructions.InstructionText FROM WorkInstructions WHERE WorkInstructions.StepNo = count" end if :confused:
You should avoid concatenating and creating SQL statements like this. At the very least, you must use paramaterized queries (http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]) Regards Senthil _____________________________ My Blog | My Articles | WinMacro