1、数据库设计:ID,Name,ParaentID,Detail
2、代码:
   
 1
   public string[] GetDeptID(int DeptID)
2
    {
3
        string PersonName = "";
4
        // int id = (int)AppendixID;
5
        SqlConnection conn;
6
        SqlCommand comm;
7
        MX.Data.Connection myconn = new MX.Data.Connection();
8
        conn = myconn.SqlConnection;
9
        string sSql = "select ID  from Sys_Org_Info  where ParentID = " + DeptID;
10
        comm = new SqlCommand(sSql, conn);
11
        conn.Open();
12
        SqlDataReader rs = comm.ExecuteReader();
13
        while(rs.Read())
14
        {
15
            arr[i++] = rs["ID"].ToString().Trim();
16
17
        }
18
        conn.Close();
19
        if(j<i)
20
        {
21
            GetDeptID(Convert .ToInt32(arr[j++]));
22
        }
23
        return arr;
24
25
    }
26
前台获取的代码:
27
string[] deptarr = Dept.GetDeptID(DeptID);
28
        for (int k = 0; k < deptarr.Length; k++)
29
        {
30
            if (deptarr[k] != null)
31
                strdept += deptarr[k] + ",";
32
        }
33
        strdept += DeptID.ToString(); 
34
   public string[] GetDeptID(int DeptID)2
    {3
        string PersonName = "";4
        // int id = (int)AppendixID;5
        SqlConnection conn;6
        SqlCommand comm;7
        MX.Data.Connection myconn = new MX.Data.Connection();8
        conn = myconn.SqlConnection;9
        string sSql = "select ID  from Sys_Org_Info  where ParentID = " + DeptID;10
        comm = new SqlCommand(sSql, conn);11
        conn.Open();12
        SqlDataReader rs = comm.ExecuteReader();13
        while(rs.Read())14
        {15
            arr[i++] = rs["ID"].ToString().Trim();16

17
        }18
        conn.Close();19
        if(j<i)20
        {21
            GetDeptID(Convert .ToInt32(arr[j++]));22
        }23
        return arr;24

25
    }26
前台获取的代码:27
string[] deptarr = Dept.GetDeptID(DeptID);28
        for (int k = 0; k < deptarr.Length; k++)29
        {30
            if (deptarr[k] != null)31
                strdept += deptarr[k] + ",";32
        }33
        strdept += DeptID.ToString(); 34

                    
                

    
        
                
            
        
浙公网安备 33010602011771号