如何在SqlDataSource中为存储过程指定参数值
作为使用 SqlDataSource 声明性语法的新手,我试图找出一种将参数值设置为存储过程的方法。我有一个通过请求对象传递的 Client_ID,我需要在执行 SqlDataSource 的存储过程之前设置 Client_ID。
我有几个问题。
存储过程参数是否必须在 ASPX 标记中预定义,或者是否可以在代码隐藏中动态添加?
是否有人有一个示例,演示带有存储过程和参数的 SqlDataSource 标记以及在代码隐藏中设置该参数值?
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.
Does the stored procedure parameter have to be predefined in the ASPX markup or can it be added dynamically in the code-behind?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用.net 4框架,您可以...
1.它可以动态添加,但您必须提供自己的代码表达式生成器(有关更多信息参见此处)
1.1 您也可以使用不同的参数来实现相同的目标,例如:
2.
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.
这是一个通过 SqlDataSource 使用参数化查询(存储过程和文本)的相当全面的示例,包括以编程方式设置参数。 ASP.NET - 使用参数化查询SqlDataSource。
This is a fairly thorough example of using parameterized queries (Stored Procedure and Text) with SqlDataSource, including programmatically setting parameters. ASP.NET - Using Parameterized Queries with the SqlDataSource.
GetProfile 是存储的过程名称,Host 是参数名称,它是从名为 InputTextBox 的文本框检索的
GetProfile is the stored proc name and Host is parameter name, which is retreived from a texbox called InputTextBox