Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Asp.Net Session Variable in SQL Query

Posted on 2012-04-04
3
Medium Priority
?
693 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 1000 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

Industry Leaders: 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

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 …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 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