简体   繁体   中英

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

ex: 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. How would I do this?

Do I need to set the output parameter for sp_selectyear?

You can pull the selected year from the drop-down list control's SelectedValue property. So you should be able to call the *sp_deleteyear* inside the button click handler, using myDropdownList.SelectedValue as the stored procedure parameter.

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;

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

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

NOTE: you don't need to use the OUTPUT parameter. It can be handled using normal parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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