无坚不摧的是信念

treeview递归

 public TreeNode fillnode(TreeNode tn)//递归
    {
        SqlConnection con = DB.creation();
        con.Open();
       
        SqlDataAdapter sda = new SqlDataAdapter("select LID,RID from huiyuan where HyID='" + tn.Text + "'", con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        con.Close();
        if (ds.Tables[0].Rows.Count>0)
        {
            if (!Convert.IsDBNull(ds.Tables[0].Rows[0]["lid"]))
            {
                TreeNode tnl = new TreeNode();
              
                tnl.Text = ds.Tables[0].Rows[0]["lid"].ToString();
                tnl = fillnode(tnl);
                tn.ChildNodes.Add(tnl);
            }
            if (!Convert.IsDBNull(ds.Tables[0].Rows[0]["rid"]))
            {
                TreeNode tnr = new TreeNode();
                tnr.Text = ds.Tables[0].Rows[0]["rid"].ToString();
                tnr = fillnode(tnr);
                tn.ChildNodes.Add(tnr);
            }
        }
        return tn;

    }

posted on 2008-08-05 16:26    阅读(845)  评论(1编辑  收藏  举报