如何在SqlDataSource的存储过程中指定的参数值 [英] How to specify parameter value for stored procedure in SqlDataSource

查看:196
本文介绍了如何在SqlDataSource的存储过程中指定的参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为新使用的SqlDataSource的声明语法,我试图找出一种方法来一个参数的值设置为一个存储过程。我有一个是通过请求对象通过了CLIENT_ID,我需要执行的SqlDataSource的存储过程之前设置CLIENT_ID。

我有几个问题。


  1. 是否存储过程的参数必须在ASPX标记pdefined $ P $还是可以在$ C $动态添加C-后面?


  2. 有没有人有一个演示的SqlDataSource标记与存储过程和参数的例子,以及设置在该参数值code-后面?



解决方案

使用.NET框架4,你可以...

1.It可以动态添加,但你必须提供自己的code EX pression建设者(更多信息的在这里看到
1.1你也可以使用不同的参数来实现同样的目标,如:

2

 < ASP:SqlDataSource的ID =SqlDataSource1=服务器
  的ConnectionString =下;%$的ConnectionStrings:yourConnectionString%>中
  的SelectCommand =YourStoreProcedureSelectCommandType =StoredProcedure的>
  < SelectParameters>
     < ASP:ControlParameter NAME =yourParameterName控件ID =controlThatHoldsParameterValue属性名=TEXT/>
  < / SelectParameters>

Being new to using the declarative syntax of SqlDataSource I am trying to figure out a way to set the value of a parameter to a stored procedure. I have a Client_ID that is passed via the Request Object and I need to set the Client_ID before the stored procedure of the SqlDataSource is executed.

I have a couple of questions.

  1. Does the stored procedure parameter have to be predefined in the ASPX markup or can it be added dynamically in the code-behind?

  2. Would anyone have an example that demonstrates the SqlDataSource markup with a stored procedure and parameter as well as setting that parameter value in code-behind?

解决方案

With .net 4 framework you can ...

1.It can be added dynamically, but you would have to provide your own code expression builder (for further info see here) 1.1 You can also use different parameter to achieve same goal, like :

2.

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

这篇关于如何在SqlDataSource的存储过程中指定的参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆