首页新闻找找看学习计划

treeList 的问题

0
悬赏园豆:10 [已解决问题] 解决于 2014-07-29 13:28

在网上看到一个博客关于TreeList的,做了个小程序

博客地址:

http://blog.csdn.net/fwj380891124/article/details/6888077

显示不出来数据,大家看看是哪里有问题

 

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public string connectionString = "server=.;database=Room;uid=sa;pwd=sa";

        private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            string sqltxt = "select * from dbo.house";
            SqlCommand cmd = new SqlCommand(sqltxt, con);
            cmd.ExecuteNonQuery();                               
            BindData();    
            con.Close();        
        }
       
        private void BindData()
        {
            DataTable dtHourse = new DataTable("house");
            this.treeListHouse.DataSource = dtHourse.TableName;
            treeListHouse.KeyFieldName = "OfficeID";
            //tlOffice.DataMember = "OfficeName";
            //treeListHouse.Columns["OfficeName"].Caption = "商品名称";
            treeListHouse.ParentFieldName = "ParentOfficeID";   
        }

男人要爽的主页 男人要爽 | 初学一级 | 园豆:15
提问于:2014-07-27 13:35
< >
分享
最佳答案
0

  DataTable dtHourse = new DataTable("house");
 this.treeListHouse.DataSource = dtHourse.TableName;

你的dataTable是你自己new的,不是从数据库里面读出来的

收获园豆:5
刘宏玺 | 专家六级 |园豆:14004 | 2014-07-27 23:30
其他回答(1)
0

            DataTable dtHourse = new DataTable("house");
            this.treeListHouse.DataSource = dtHourse.TableName;

    DataTable dtHourse = new DataTable("house"); 自己new的会有数据吗?

    DataSource = dtHourse.TableName; 合理吗?

收获园豆:5
Moral | 园豆:206 (菜鸟二级) | 2014-07-28 22:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册