简体   繁体   English

在按钮中执行存储过程

[英]Execute stored procedure in button

I have a drop down list binded to a stored procedure sp_selectyear that shows the distinct years from a column in a table 我有一个绑定到存储过程sp_selectyear的下拉列表,该列表显示表中列的不同年份

ex: 2010 2011 2012 例如:2010 2011 2012

I want to execute another stored procedure sp_deleteyear on a button that deletes those rows/records based on the year selected in the drop down list. 我想在按钮上执行另一个存储过程sp_deleteyear,该按钮将根据下拉列表中选择的年份删除这些行/记录。 How would I do this? 我该怎么做?

Do I need to set the output parameter for sp_selectyear? 我是否需要为sp_selectyear设置输出参数?

You can pull the selected year from the drop-down list control's SelectedValue property. 您可以从下拉列表控件的SelectedValue属性中拉出选定的年份。 So you should be able to call the *sp_deleteyear* inside the button click handler, using myDropdownList.SelectedValue as the stored procedure parameter. 因此,您应该能够使用myDropdownList.SelectedValue作为存储过程参数,在按钮单击处理程序中调用* sp_deleteyear *。

You can actual get the id from dropdownlist using c# by SelectValue property and then you can pass at as normal parameter to your store procedure like this; 您可以使用c#的SelectValue属性从下拉列表中实际获取ID,然后可以像这样将其作为常规参数传递给存储过程;

CREATE PROC sp_selectyear
(
     @yearId (your datatype)
)
AS

DELETE FROM [TableName]
WHERE [ColiD] = @yearId

NOTE: you don't need to use the OUTPUT parameter. 注意:您不需要使用OUTPUT参数。 It can be handled using normal parameter. 可以使用常规参数进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM