Solved

Asp.Net Session Variable in SQL Query

Posted on 2012-04-04
3
685 Views
Last Modified: 2012-04-07
Hi,

I'm trying to use a session variable in an SQL for a grid:

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
            SelectCommand="SELECT [id], [RecordedDate]  FROM [tbl_obs] Where [Company]=@CompanyName">
        <SelectParameters><asp:SessionParameter DefaultValue="ABC Limited" Name="CompanyName" SessionField="CompanyName" Type="String" /></SelectParameters>
        </asp:SqlDataSource>

Open in new window


I keep recieving an error message:

Exception Details: System.Data.OleDb.OleDbException: Must declare the scalar variable "@CompanyName".

What am doing wrong?

Thanks
0
Comment
Question by:sanjshah12
3 Comments
 
LVL 19

Expert Comment

by:Manoj Patil
ID: 37808359
Hi, in your post it looks like everything is working fine...
Have you check the Spelling because it is case sensitive.
0
 
LVL 12

Accepted Solution

by:
Pra4444 earned 250 total points
ID: 37808508
You may have to replace questionmark (?) instead of @ in your query for oledb...

SelectCommand="SELECT [id], [RecordedDate]  FROM [tbl_obs] Where [Company]=?"

http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx
0
 

Author Closing Comment

by:sanjshah12
ID: 37819228
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now