GRIDVIEW achieve move down the stored procedure

Build a table t_hoteladvertise

There are the following fields:
ID Automatic growth (primary)
SortID of the INT (mainly)
the Title NVARCHAR (50)

 

CREATE proc sp_ehotel_DownAdvertise

@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE INT @TempID

BEGIN  TRAN

SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID

SELECT @ TempSortID = max (outputs) Departures from t_hoteladvertise wheres> @SortID
SELECT @ TempID = [ID] from t_hoteladvertise WHERE
exit = @ TempSortID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID

 NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO


CREATE proc sp_ehotel_UpAdvertise
@ID INT
as
DECLARE @SortID int
DECLARE @TempSortID INT
DECLARE @TempID INT

BEGIN  TRAN

SELECT @SortID=SortID  from t_hoteladvertise where [ID]=@ID

SELECT @ TempSortID = max (outputs) Departures from t_hoteladvertise wheres <@SortID
SELECT @ TempID = [ID] from t_hoteladvertise WHERE
exit = @ TempSortID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@SortID WHERE [ID]=@TempID

if @@error>0 or @@rowcount<>1
goto NeedRollBack

UPDATE t_hoteladvertise SET SortID=@TempSortID where [ID]=@ID

 NeedRollBack:
if @@error>0 or @@rowcount<>1
  rollback tran
else
commit tran
GO



代码段:
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        SqlConnection conn = new SqlConnection();

       if (e.CommandName == "down")
        {
            int IndexID = Convert.ToInt32(e.CommandArgument);
            try
            {
                XMLData.OpenDatabase(conn);
                XMLData.ExecuteNonQuery(conn, "SP_EHOTEL_UPADVERTISE", IndexID);
                Label2.Visible = true;
                Label2.Text = "下移成功!";
            }
            catch (Exception)
            {
                Response.Write("<script language='javascript'>alert('下移出错,点取消返回');</" + "script>");
            }
            finally
            {
                XMLData.CloseDatabase(conn);
                BindAdvertise();
            }
        }
        if (e.CommandName == "up")
        {
            int IndexID = Convert.ToInt32(e.CommandArgument);
            try
            {
                XMLData.OpenDatabase(conn);
                XMLData.ExecuteNonQuery(conn, "SP_EHOTEL_DOWNADVERTISE", IndexID);
                Label2.Visible = true;
                Label2.Text = "上移成功!";
            }
            catch (Exception)
            {
                Response.Write("<script language='javascript'>alert('上移出错,点取消返回');</" + "script>");
            }
            finally
            {
                XMLData.CloseDatabase(conn);
                BindAdvertise();
            }
        }
    }

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2007/04/23/724352.html

Guess you like

Origin blog.csdn.net/weixin_34246551/article/details/93495909