treeview 绑定 datatable 或 dataset 添加节点

该博客展示了如何在C# WinForms应用程序中将数据库中的数据(使用DataTable和Dataset)绑定到TreeView控件,以创建一个显示数据的树形结构。通过执行SQL查询获取数据,然后遍历数据填充TreeNode,实现数据的可视化展示。
摘要由CSDN通过智能技术生成
namespace treeview2
{
    public partial class Form1 : Form
    {
        private static string connString = "Data Source=.;Initial Catalog=***;Integrated Security=True";
        public static SqlConnection connection = new SqlConnection(connString);
        private DataTable datatable;
        SqlDataAdapter dataAdapter;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            BindTree();
        }

        private DataTable getTreeViewData()
        {
            string sql = "select no,title from b_table";
            try
            {
                datatable = new DataTable();
                dataAdapter = new SqlDataAdapter(sql, connec
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值