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. Web Development
  3. ASP.NET
  4. Problem with scalar variable [modified]

Problem with scalar variable [modified]

Scheduled Pinned Locked Moved ASP.NET
helpdatabase
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.
  • A Offline
    A Offline
    aqzman_
    wrote on last edited by
    #1

    Hey guys, I'm having a small problem with a scalar variable. I took the code from another project I wrote but there were a few changes in this new project so I wasn't able to do the same thing as last time. Anyway, now I'm getting the error "Must declare the scalar variable "@State".", mostly because I'm not exatly sure where to declare it. The code is a bit scattered, but I'll try to make it as short as I can, without leaving anything out. Although I think the problem is in the SqlDataSource with the select prameters / control parameter EDIT: In hindsight I really should have specified what I'm trying to do. There is a drop down list where users will pick a state of a variable from a database, then the infomation matching that state will be displayed accordingly. Drop Down List: The SqlDataSource: The VB/SQL code which would interact with the "@State": Dim cmd As New SqlCommand("SELECT * FROM tblTicket ... WHERE ... tblTicket.State = @State", New SqlConnection(strCon)) cmd.Connection.Open() Dim myReader As SqlDataReader = cmd.ExecuteReader() The actual error I was talking about ("Must declare the scalar variable "@State".") comes up at 'Dim myReader As SqlDataReader = cmd.ExecuteReader()', so I pretty much know that I just have the variable delared in the wrong place. I'd really appreciate any help, and if any more code is needed I'll post it right away. Thanks, aqzman

    G 1 Reply Last reply
    0
    • A aqzman_

      Hey guys, I'm having a small problem with a scalar variable. I took the code from another project I wrote but there were a few changes in this new project so I wasn't able to do the same thing as last time. Anyway, now I'm getting the error "Must declare the scalar variable "@State".", mostly because I'm not exatly sure where to declare it. The code is a bit scattered, but I'll try to make it as short as I can, without leaving anything out. Although I think the problem is in the SqlDataSource with the select prameters / control parameter EDIT: In hindsight I really should have specified what I'm trying to do. There is a drop down list where users will pick a state of a variable from a database, then the infomation matching that state will be displayed accordingly. Drop Down List: The SqlDataSource: The VB/SQL code which would interact with the "@State": Dim cmd As New SqlCommand("SELECT * FROM tblTicket ... WHERE ... tblTicket.State = @State", New SqlConnection(strCon)) cmd.Connection.Open() Dim myReader As SqlDataReader = cmd.ExecuteReader() The actual error I was talking about ("Must declare the scalar variable "@State".") comes up at 'Dim myReader As SqlDataReader = cmd.ExecuteReader()', so I pretty much know that I just have the variable delared in the wrong place. I'd really appreciate any help, and if any more code is needed I'll post it right away. Thanks, aqzman

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Most of your markup is not visible. Use the "Ignore HTML" option when you are posting markup code. You have to add a parameter to the command object. The parameter that you have added to the SqlDataSource isn't used, as you don't use the SqlDataSource.

      --- single minded; short sighted; long gone;

      A 1 Reply Last reply
      0
      • G Guffa

        Most of your markup is not visible. Use the "Ignore HTML" option when you are posting markup code. You have to add a parameter to the command object. The parameter that you have added to the SqlDataSource isn't used, as you don't use the SqlDataSource.

        --- single minded; short sighted; long gone;

        A Offline
        A Offline
        aqzman_
        wrote on last edited by
        #3

        Oh, thanks for letting me know about that. I really should have looked over my message once it was posted. I'm not exatly sure what you mean by it isn't used, the SqlDataSource is called in DataSourceID of the dropdownlist. Or maybe I've misunderstood you. Thanks for the help! aqzman

        G 1 Reply Last reply
        0
        • A aqzman_

          Oh, thanks for letting me know about that. I really should have looked over my message once it was posted. I'm not exatly sure what you mean by it isn't used, the SqlDataSource is called in DataSourceID of the dropdownlist. Or maybe I've misunderstood you. Thanks for the help! aqzman

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          aqzman_ wrote:

          I'm not exatly sure what you mean by it isn't used, the SqlDataSource is called in DataSourceID of the dropdownlist. Or maybe I've misunderstood you.

          The SqlDataSource is used on the page, but it's not used in the code that you have problems with.

          --- single minded; short sighted; long gone;

          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