求各位前辈写个方法,比如有张表 部门表 dept(deptid,parentid),就是部门ID 和上一级的ID 我现在要实现下面的方法
 我递归不怎么会用 求大家指点
 public void getAll(int a)
{
    //得到deptid=a,和他所有子节点的信息
}谢谢!

解决方案 »

  1.   


       private void Form1_Load(object sender, EventArgs e)
            {
                DataTable _Table = new DataTable();
                _Table.Columns.Add("DeptID");
                _Table.Columns.Add("DeptName");
                _Table.Columns.Add("DeptParentID");
                _Table.Rows.Add(new object[] {1,"根节电1",0 });
                _Table.Rows.Add(new object[] { 2, "根节电2", 0 });
                _Table.Rows.Add(new object[] { 3, "子节点1", 1 });
                _Table.Rows.Add(new object[] { 4, "子节点2", 1 });
                _Table.Rows.Add(new object[] { 5, "子节点3", 1 });            _Table.Rows.Add(new object[] { 6, "子节点A", 2 });
                _Table.Rows.Add(new object[] { 7, "子节点B", 2 });
                _Table.Rows.Add(new object[] { 8, "子节点C", 2 });
                _Table.Rows.Add(new object[] { 9, "子点A", 3 });
                _Table.Rows.Add(new object[] { 10, "子点B", 6 });            IList<DataRow> _RowList = new List<DataRow>();
                GetDeptRow("1", _Table, _RowList);        }        public void GetDeptRow(string p_DeptID,DataTable p_DeptTable,IList<DataRow> p_DeptRowList)
            {            DataRow[] _DeptRowList = p_DeptTable.Select("DeptParentID=" + p_DeptID.ToString());
                for (int i = 0; i != _DeptRowList.Length; i++)
                {
                    p_DeptRowList.Add(_DeptRowList[i]);
                    GetDeptRow(_DeptRowList[i]["DeptID"].ToString(), p_DeptTable, p_DeptRowList);
                }        }
      

  2.   

    http://zhidao.baidu.com/question/81358057.html
      

  3.   

    我要自己读数据库啊 你table是自己加的,而且不太适合我要的方法,谁还有更好的方法 写下 谢谢!