将Treeview数据插入数据库 [英] Inserting treeview data to database

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

问题描述

大家好,

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

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

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();
 
        }
    }
}




在brk点的帮助下,我知道在foreach循环中未创建类型为"Treenode"的tat对象.请帮助代码.



thnx




with the help of brk points i came to know tat object of type "Treenode" in foreach loop is not getting created. please help with the code.



thnx

推荐答案


请参考以下链接
如何使用C#在TreeView中查找所有选中的节点 [ ^ ]
进一步阅读
http://msdn.microsoft.com/en-us/library/system. windows.forms.treeview.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.checkednodes.aspx [
Hi,
Please refer below links
How to find all the checked nodes in TreeView using C#[^]
Further reading
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[^]
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.checkednodes.aspx[^]


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

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