Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sql Datasource and Parameters

Posted on 2011-09-06
4
Medium Priority
?
342 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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