How to specify a parameter value for a stored procedure in SqlDataSource

Being new to using the declarative syntax of SqlDataSource, I'm trying to figure out a way to set a parameter value in a stored procedure. I have a Client_ID that is passed through the Request object, and I need to set the Client_ID before the SqlDataSource stored procedure is executed.

I have a few questions.

  • Should the stored procedure parameter be predefined in the ASPX markup or can it be added dynamically in the code?

  • Will anyone have an example demonstrating the markup of a SqlDataSource with a stored procedure and parameter, as well as setting this parameter value in the code?

+5
source share
3 answers

With a .net 4 card you can ...

1. It can be added dynamically, but you will need to provide your own constructor of code expressions ( see here for more information ) 1.1 You can also use another parameter to achieve the same goal, for example:

enter image description here

2.

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  ConnectionString="<%$ ConnectionStrings:yourConnectionString %>" 
  SelectCommand="YourStoreProcedure" SelectCommandType="StoredProcedure">
  <SelectParameters>
     <asp:ControlParameter Name="yourParameterName" ControlID="controlThatHoldsParameterValue" PropertyName="Text" />
  </SelectParameters>

+9
source

This is a fairly detailed example of using parameterized queries (stored procedure and text) with SqlDataSource, including programmatic settings. ASP.NET - Using parameterized queries using SqlDataSource .

+3
source
 <asp:SqlDataSource ID="ADSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ADConnection %>"
    SelectCommand="GetProfile" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="InputTextBox" Name="Host" PropertyName="Text" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

GetProfile - proc Host, texbox InputTextBox

0
source

All Articles