Solved

Asp.Net Session Variable in SQL Query

Posted on 2012-04-04
3
690 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

759 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