Solved

Asp.Net Session Variable in SQL Query

Posted on 2012-04-04
3
691 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

617 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