GRIDVIEW中实现上移下移的存储过程上海时时乐走势

    SELECT
    @ErrorMessage = ERROR_MESSAGE(),
    @ErrorSeverity = ERROR_SEVERITY(),
    @ErrorState = ERROR_STATE();

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(SortID) from t_hoteladvertise where SortID<@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@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 PROCEDURE [dbo].[测验用勿删]
@userid  int,    
@return int    out
AS
begin try
    BEGIN TRAN
    print 1/1
    COMMIT TRAN
    print '成功了'
END try
BEGIN catch
   ROLLBACK
   print '回滚了'
    DECLARE @ErrorMessage NVARCHAR(4000);
    DECLARE @ErrorSeverity INT;
    DECLARE @ErrorState INT;

建二个表  t_hoteladvertise
有如下字段:
ID  自动增加(首要)
SortID  INT (主要)
Title  NVARCHAR(50)
代码:

-- =============================================
--带参输出的积累进程
--测量试验方法:
--declare @return int
--exec 测量试验用勿删  1, @return out
--print @return
-- =============================================

CREATE proc sp_ehotel_DownAdvertise
@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(SortID) from t_hoteladvertise where SortID>@SortID
SELECT @TempID=[ID] from t_hoteladvertise WHERE SortID=@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

    RAISERROR (@ErrorMessage, -- Message text.
    @ErrorSeverity, -- Severity.
    @ErrorState -- State.
    );
end catch
set @return=@userid 20

            catch (Exception)
            {
                Response.Write("<script language='javascript'>alert('上移出错,点裁撤再次来到');</" "script>");
            }
            finally
            {
                XMLData.CloseDatabase(conn);
                BindAdvertise();
            }
        }
    }

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 = "上移成功!";
            }

本文由上海时时乐走势图发布于上海时时乐走势图官网,转载请注明出处:GRIDVIEW中实现上移下移的存储过程上海时时乐走势

您可能还会对下面的文章感兴趣: