Solved

Sql Datasource and Parameters

Posted on 2011-09-06
4
333 Views
Last Modified: 2012-05-12
I have not used a sql data source before and I'm doing some updates on an existing web site.
In the basepage class that all of the aspx pages inherit from is a property called Culture of type string.
I added the parameter below, is this correct? Do I need to specify anything else or will it extract the value from the property?
 
            <SelectParameters>
                  <asp:QueryStringParameter Name="ProductID" QueryStringField="prodid" Type="Int32" />
                  <asp:Parameter Name="Culture" Type="String" />
            </SelectParameters>
0
Comment
Question by:JRockFL
[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
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:ivan_vagunin
ID: 36488540
Hi!
I guess you need to set value for parameter, because it will not be binded automatically:
<asp:Parameter Name="Culture" Type="String"  DefaultValue="<%= this.Culture %>"/>
0
 
LVL 8

Author Comment

by:JRockFL
ID: 36488591
it looks like it is passing that literal value.

This is what it looks like from the sql server trace
exec usp_ListSubProductsByProductID @ProductID=1156,@Culture=N'<%= this.Culture %>'
0
 
LVL 18

Accepted Solution

by:
ivan_vagunin earned 500 total points
ID: 36488667
Yes, sorry. It looks like the expression for Default value gets encoded, so the code is not executed... Here is a solution: http://peterkellner.net/2006/09/18/expressionbuilderidentity/, but I guess this is quite complex.
So one option is to create your own parameter class inherited from asp:Parameter. Another is to init DefaultValue from code behind:
protected void OnInit(EventArgs e)
{
   base.OnInit(e);
   MySqldataSource.SelectParameters["Culture"].DefaultValue = Culture;
}
Look this discussion: http://forums.asp.net/t/1115044.aspx/1?Passing+Parameters+for+SqlDataSource+from+code+behind
0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 36488730
Awesome, thank you
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

Title # Comments Views Activity
What are the simplest ways to create a Merge Sort? 3 36
Why use this lambda? 12 63
Record locking on classic ASP 3 39
Display info from DB to Label in asp.net 7 14
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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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