Database DB = new Database();
                        string Paren_sql = "select * From ArticleClass where ParentPath like '%" + ParentPath + ClassID.ToString() + "%'";
                        DataTable Paren_td = DB.GetDataTable(Paren_sql);//
                        foreach (DataRow Paren_dr in Paren_td.Rows)
                        {
                            mParentPath = ParentPath.Replace(Paren_dr["ParentPath"].ToString(), "");
                            //ClientScript.RegisterStartupScript(this.GetType(), "", " <script>alert('" + mParentPath + "!');location.href='Admin_Class_Article.aspx';</script>");
                            db.ExecuteSQL("update ArticleClass set Depth=Depth-" + Depth + ",RootID=" + MaxRootID + ",ParentPath='" + mParentPath + "' where ClassID=" + Convert.ToInt32(Paren_dr["ClassID"].ToString()));
                        }int i=0;
Database ParenDB = new Database();
                        SqlDataReader Paren_Rs = ParenDB.GetDataReader("select * From ArticleClass where ParentPath like '%" + ParentPath + ClassID.ToString() + "%'");
                        while (Paren_Rs.Read())
                        {
                            i++;
                            mParentPath = ParentPath.Replace(Paren_Rs["ParentPath"].ToString(), "");
                            db.ExecuteSQL("update ArticleClass set Depth=Depth-" + Depth + ",RootID=" + MaxRootID + ",ParentPath='" + mParentPath + "' where ClassID=" + Convert.ToInt32(Paren_Rs["ClassID"].ToString()));
                        }
                        Paren_Rs.Close();这二种方法的效果相同否,哪一种更好

解决方案 »

  1.   

    我喜欢第三种 db.ExecuteSQL("update ArticleClass set Depth=Depth-" + Depth + ",RootID=" + MaxRootID + ",ParentPath='" + mParentPath + "' where ClassID IN(SELECT ClassID From ArticleClass where ParentPath like '%" + ParentPath + ClassID.ToString() + "%') ");
      

  2.   

    就一第种和第二种而言, datareader比较省资源,但是是基于连接的,而你同时还要更新同一张表,这样就有可能造成死锁,所以还是第一种较好.
      

  3.   

    就你目前的代码来看是可行的.除非你省略了什么关键代码,如Depth 的取值是否与查询有关等.
      

  4.   

    此方法最好,基本不会造成问题,再加一个transtion就更完美了
      

  5.   


    ClassID与查询相关呀,有多个ClassID。谢谢