• 获取所有子节点 父亲节点


    //子节点

      Expo.Database.SqlGen mycmd = new Expo.Database.SqlGen();
        protected void Page_Load(object sender, EventArgs e)
        {
            IList<string> path = new List<string>();
            GetPath(2, ref path);

            foreach (string s in path) {
                Response.Write(s + "<br/>");
            }
        }


        public void GetPath(int father,ref IList<string> path)
        {
            string strsql = "select id,title,father from t_Area where father=" + father.ToString();
            using (SqlDataReader dr1 = mycmd.ExecuteReader(strsql))
            {
                if (!dr1.HasRows)
                    return;
                while (dr1.Read())
                {
                    path.Add(dr1["title"].ToString());
                    GetPath(Convert.ToInt32(dr1["id"]),ref path);
                }
                dr1.Close();
                dr1.Dispose();
            }
        }

     

     

    //父亲节点

     string strsql = @" declare @tempTable TABLE
                                (
                                 [id] int,
                                 Name varchar(50),
                                 Depth int,
                                 ParentID int,
                                 Rank int
                                )
                                declare @ID int
                                set @ID={0}
                                while(@ID>0)
                                begin
                                    select @ID=ParentID from t_Category where ID=@ID;
                                    if(@ID>0)
                                    begin
                                    insert into @tempTable select * from t_Category where ID=@ID;
                                    end
                                end
                                select * from @tempTable order by id ";

  • 相关阅读:
    C语言之基本算法24—黄金切割法求方程近似根
    windows下PHP不能开启pgsql扩展的解决方法
    Linux 文件基本属性
    Android倒计时功能的实现
    hdu2444The Accomodation of Students (最大匹配+推断是否为二分图)
    Asp.net core使用IIS在windows上进行托管
    [Asp.net]web.config customErrors 如何设置?
    [Asp.net mvc]Html.ValidationSummary(bool)
    [C#基础]说说lock到底锁谁?(补充与修改)
    [web.config]如何灵活使用配置文件
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1455739.html
Copyright © 2020-2023  润新知