树视图到数据库 [英] treeview to database

查看:80
本文介绍了树视图到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个项目,其中有一个树状视图,并且它是从数据库中填充的,我想在单击按钮后将树状视图中的选中项插入数据库中,我没有得到如何在树状视图中插入选中的项到我的按钮单击事件中的代码如下所示.任何人都可以帮助我...非常紧急...请...帮助我..

Hello all,

I am developing a project in which I am having a treeview and it is populated from the database, I want to insert the checked item in treeview to database after clicking a button, I am not getting how to insert the checked item in tree view to database.My code in button click event looks like this. Can any one help me...its very urgent...please...help me..

protected void btn1_Click(object sender, EventArgs e) 
{ 
     SqlConnection con = new SqlConnection("Data Source=GAYATHRI\SQLEXPRESS;Initial      Catalog=VOY_SERVICES1;Integrated Security=True"); con.Open();
 
    foreach (TreeNode tnode in TreeView1.CheckedNodes)
    {
        if (tnode.Checked == true)
        { 
            string strTreeValue;
            strTreeValue = tnode.Value;
            SqlCommand com = new SqlCommand("insert into treeview_select(subdisease_name) values(@name)", con);
 
            com.Parameters.AddWithValue("@name", strTreeValue);
            com.ExecuteNonQuery();
            con.Close(); 
        }
    }
}

推荐答案

tnode.Value不太可能是您要保存到数据库的值,并且可能为空.我怀疑您要保存tnode.Text,它将是树中显示的值.
tnode.Value is unlikely to be the value you want to save to the DB and is probably empty. I suspect you want to save tnode.Text, which will be the value displayed in your tree.


这篇关于树视图到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆