Solved

Sql Datasource and Parameters

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

12 Experts available now in Live!

Get 1:1 Help Now