1
2
3
4
5
……
N把4删除后
5变成4
N变成N-1

解决方案 »

  1.   

    DELETE FROM table WHERE xx=4
    UPDATE table SET xx=xx - 1 WHERE xx > 4
      

  2.   

    写是这样写,感觉挺简单,但是NND在我这边连续删除几次就出错。Db.Category myCategory = new Category();
    DataSet ds = myCategory.dsSelectOrderBy();
    if(txtOrderNum.Text == maxOrderNum.ToString())
    {
    if(myCategory.DelPCategory(int.Parse(txtOrderNum.Text),int.Parse(txtDeepNum.Text)) == "1")
    {
    Response.Write("<script>alert('删除成功!')</script>"); delCategoryBind();
    txtBind();
    }
    else
    {
    Response.Write("<script>alert('删除失败!')</script>");
    }
    }
    else
    {
    if(myCategory.DelPCategory(int.Parse(txtOrderNum.Text),int.Parse(txtDeepNum.Text)) == "1")
    {
    for(int i=int.Parse(txtOrderNum.Text);i<ds.Tables[0].Rows.Count;i++)
    {
    myCategory.DelUpdate(i+1,int.Parse(txtOrderNum.Text));
    } Response.Write("<script>alert('删除成功!')</script>"); tvCategoryBind();
    txtBind();
    }
    else
    {
    Response.Write("<script>alert('删除失败!')</script>");
    }
    }
      

  3.   

    靠,删除之后要这样更新。
    ALTER PROCEDURE Sp_Category_DelUpdateOrderNum
    @OrderNum int
    AS
    UPDATE Category
    SET OrderNum = @OrderNum
    WHERE (OrderNum > @OrderNum - 1)
    RETURN