Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Can you pass a local variable into sql statement?

Can you pass a local variable into sql statement?

Scheduled Pinned Locked Moved Visual Basic
databasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spettiford
    wrote on last edited by
    #1

    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:

    O S 3 Replies Last reply
    0
    • S spettiford

      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:

      O Offline
      O Offline
      oakleaf
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • O oakleaf

        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

        S Offline
        S Offline
        spettiford
        wrote on last edited by
        #3

        THANK YOU!!! I knew there was a way, but just didn't get the syntax correct. It works great and you saved me.:-D

        1 Reply Last reply
        0
        • S spettiford

          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:

          O Offline
          O Offline
          oakleaf
          wrote on last edited by
          #4

          your welcome and for string variables: myConn_.CommandText = "SELECT BLAH FROM BLAH_TABLE_NAME WHERE BLAH_TABLE_NAME.BLAHCOLUMN_NAME (OPERATOR)'" & report_type & "'"

          1 Reply Last reply
          0
          • S spettiford

            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:

            S Offline
            S Offline
            S Senthil Kumar
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups