Scalar Variable Error

I'm setting the below sql datasources in my aspx.vb file and I'm getting a 'must declare scalar variable' error

I know why its happening but I don't know how to declare the session variable the the @seSchemeIDis looking for.

Below is the code, and the session variable it is looking for is set in the previous page and can be called in the pageload event.  I just don't know how to do it before that.


Thanks

Imports System.Web.UI.WebControls
Partial Class mqsquote
 
    Inherits System.Web.UI.Page
 
 
    Dim dataSource1 As SqlDataSource = New SqlDataSource(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString, "SELECT UseLenderVal FROM [vwSchemes] WHERE ([SchemeID] = @seSchemeID as Test")
 
    Dim dataSource2 As SqlDataSource = New SqlDataSource(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString, "SELECT ApplicationFee FROM tblApplicationFees Where (@PurchasePrice  BETWEEN [Lower] AND [Higher])")

Open in new window

EdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
If you are dynamically generating an SqlDataSource, and you know what the parameters are, then you could do something like this:


    Dim connectionString As String = ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
 
    Dim commandText1 As String = String.Format("SELECT UseLenderVal FROM [vwSchemes] WHERE ([SchemeID] = {0} as Test", Session("SchemeID"))
    Dim commandText2 As String = String.Format("SELECT ApplicationFee FROM tblApplicationFees Where ({0} BETWEEN [Lower] AND [Higher])", Session("PurchasePrice"))
 
    Dim dataSource1 As New SqlDataSource(connectionString, commandText1)
    Dim dataSource2 As New SqlDataSource(connectionString, commandText2)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.