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. Database & SysAdmin
  3. Database
  4. Parameterised Queries in VB6

Parameterised Queries in VB6

Scheduled Pinned Locked Moved Database
helpcsharpdatabase
4 Posts 2 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.
  • D Offline
    D Offline
    David Wengier
    wrote on last edited by
    #1

    I'm trying to execute an SQL statement with parameters through a Command object. I've done it a thousand times through ADO.NETs SqlCommand object, but now i'm using ADOs Command object from vb6. Is it possible, cos its not working.

    lEntry\_ID = 5
    Dim cmd As Command
    Set cmd = New Command
    Set cmd.ActiveConnection = gConn
    cmd.CommandType = adCmdText
    cmd.Parameters.Append cmd.CreateParameter("@Entry\_ID", adInteger, adParamInput, , lEntry\_ID)
    cmd.CommandText = "SELECT \* FROM Entry WHERE ID = @Entry\_ID"
    If cmd.Execute.EOF then
         'blah
    End If
    

    I get the error "Must supply a value for variable: @Entry_ID". Any help would be appreciated. -- Dave

    R 1 Reply Last reply
    0
    • D David Wengier

      I'm trying to execute an SQL statement with parameters through a Command object. I've done it a thousand times through ADO.NETs SqlCommand object, but now i'm using ADOs Command object from vb6. Is it possible, cos its not working.

      lEntry\_ID = 5
      Dim cmd As Command
      Set cmd = New Command
      Set cmd.ActiveConnection = gConn
      cmd.CommandType = adCmdText
      cmd.Parameters.Append cmd.CreateParameter("@Entry\_ID", adInteger, adParamInput, , lEntry\_ID)
      cmd.CommandText = "SELECT \* FROM Entry WHERE ID = @Entry\_ID"
      If cmd.Execute.EOF then
           'blah
      End If
      

      I get the error "Must supply a value for variable: @Entry_ID". Any help would be appreciated. -- Dave

      R Offline
      R Offline
      rmacfadyen
      wrote on last edited by
      #2

      With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters: cmd.Parameters.Append cmd.CreateParameter("Entry_ID", adInteger, adParamInput, , lEntry_ID) cmd.CommandText = "SELECT * FROM Entry WHERE ID = ?" More or less the same was as with the ADO.NET ODBC provider. Regards, Rob -- RMTrack a new bug tracking tool. Available now from http://www.rmtrack.com

      D 1 Reply Last reply
      0
      • R rmacfadyen

        With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters: cmd.Parameters.Append cmd.CreateParameter("Entry_ID", adInteger, adParamInput, , lEntry_ID) cmd.CommandText = "SELECT * FROM Entry WHERE ID = ?" More or less the same was as with the ADO.NET ODBC provider. Regards, Rob -- RMTrack a new bug tracking tool. Available now from http://www.rmtrack.com

        D Offline
        D Offline
        David Wengier
        wrote on last edited by
        #3

        rmacfadyen wrote: With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters Thats what I was afraid of. The parameters could appear in any order in the SQL (or might not be there at all). Oh well, i'll just have to do it myself with Replace Thanks :) -- Dave

        R 1 Reply Last reply
        0
        • D David Wengier

          rmacfadyen wrote: With VB6/ADO you do not use named parameters in the CommandText... you use positional parameters Thats what I was afraid of. The parameters could appear in any order in the SQL (or might not be there at all). Oh well, i'll just have to do it myself with Replace Thanks :) -- Dave

          R Offline
          R Offline
          rmacfadyen
          wrote on last edited by
          #4

          Umm... doing it with replace is may be a bad idea unless you're careful about escaping and formatting your parameters correctly (sql injection attacks can't happen if you use parameterized queries). Are you sure the parameters could appear in any order? Regards, Rob -- RMTrack a new bug tracking tool. Available now from http://www.rmtrack.com

          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