Scalar Variable Error

Posted on 2008-02-11
Medium Priority
Last Modified: 2013-11-26
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.


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

Question by:Ed
1 Comment
LVL 96

Accepted Solution

Bob Learned earned 2000 total points
ID: 20868202
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


Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question