Solved

Asp.Net Session Variable in SQL Query

Posted on 2012-04-04
3
682 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

744 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

18 Experts available now in Live!

Get 1:1 Help Now