Problem with scalar variable [modified]
-
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
-
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
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;
-
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;
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
-
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
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;