使用存储过程删除行 [英] Deleting Rows using Stored Procedure

查看:92
本文介绍了使用存储过程删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要单击一次从asp.net删除sql表中的多行...如何为此编写存储过程... ??????

I need to delete a multiple rows in a sql table from asp.net in a single click...How to write a stored procedure for this...??????

推荐答案

http://www.daniweb.com/web -development/databases/ms-sql/threads/146829 [ http://www.java2s.com/Tutorial/SQLServer/0400__Transact-SQL/Deleterecordinastoredprocedurebyparameter.htm [ ^ ]



检查此链接...:)
http://www.daniweb.com/web-development/databases/ms-sql/threads/146829[^]

http://www.java2s.com/Tutorial/SQLServer/0400__Transact-SQL/Deleterecordinastoredprocedurebyparameter.htm[^]



check this link...:)


这是否对您有帮助:

http://www.aspsnippets.com/Articles/Select-and-delete-multiple-rows-in-ASP.Net-Gridview-control.aspx [ http://geekswithblogs.net/dotNETvinz/存档/2009/02/22/gridview-multiple-delete-with-checkbox-and-confirm.aspx [
Does this help you :

http://www.aspsnippets.com/Articles/Select-and-delete-multiple-rows-in-ASP.Net-Gridview-control.aspx[^]

Specially Deleting multiple selected rows section

and this one :
http://geekswithblogs.net/dotNETvinz/archive/2009/02/22/gridview-multiple-delete-with-checkbox-and-confirm.aspx[^]


After your comment I should say that you need to concatenate selected IDs at the application side and send them to a stored procedure. In the stored procedure you need to split received IDs by knowing the delimiter character and make a list of IDs so I have provided for you the code for the spliter :

declare @sep char(1)
declare @s varchar(max)
set @sep = ','
set @s= '16,17,18';

    WITH Pieces(pn, start, stop) AS (
      SELECT 1, cast(1 as int), CHARINDEX(@sep, @s)
      UNION ALL
      SELECT pn + 1, cast(stop + 1 as int), CHARINDEX(@sep, @s, stop + 1)
      FROM Pieces
      WHERE stop > 0
    ),shouldDelete(id) as
    (
    SELECT
      SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE LEN(@s) END) AS s
    FROM Pieces
  )
  delete from TableName where id in (select * from shouldDelete)



我从这里提取了拆分器部分:



I have extracted splitter part from here : http://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-reco[^]

16 , 17 and 18 are examples so convert @s to the parameter of stored procedure.
And remember that you have a limit of 8000 characters in case of using varchar for parameter type.

I''m sure you can handle rest of the work ;)

Good Luck




存储过程并不像ppl认为的那么困难,您只需要编写普通的delete查询并将一些参数传递给它即可.

喜欢,

Hi,

stored procedure is not that much difficult as ppl think, you only need to write normal delete query and passing some argument into it.

like,

delete * from table1 where column1 = @myParam



尽管这不能完全正常运行SP.但是我想你有主意.这里有关
创建SP的更多信息

然后从asp.net应用程序可以调用此SP. 在ASP.NET中执行SP

希望这对您有帮助,

谢谢
-Amit,



although this is not fully working SP. but i think you got idea. Here more info about Creating SP

then from asp.net application you can call this SP. Execute SP in ASP.NET

Hope this will help you,

thanks
-Amit,


这篇关于使用存储过程删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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