Solved

Sql Datasource and Parameters

Posted on 2011-09-06
4
330 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now