C#treeview控件与access同步更新问题 5
我用3个for循环读取access3张表,形成3级树的treeview,如何对treeview的树添加,删除,修改后同步到数据库?...
我用3个for循环读取access3张表,形成3级树的treeview,如何对treeview的树添加,删除,修改后同步到数据库?
展开
展开全部
看了一下,这个比较适合你4922这是完整代码private DataSet ds; private SqlDataAdapter sqlDataAdapter1; private int maxnodeid; private void Form1_Load(object sender, System.EventArgs e) { string strconn=ConfigurationSettings.AppSettings["ConnStr"]; sqlConnection1 = new SqlConnection(strconn); this.sqlConnection1.Open(); //填充DataSet this.CreateDataSet(); //从数据库中读取数据,通过递归生成树 InitTree(this.treeView1.Nodes,"0"); } private void CreateDataSet() { this.sqlDataAdapter1=new SqlDataAdapter("select * from s_menu ",this.sqlConnection1); this.ds=new DataSet(); this.sqlDataAdapter1.Fill(ds,"tree"); } private void InitTree(TreeNodeCollection Nds,string parentId) { DataView dv=new DataView(); TreeNode tmpNd; string intId; dv.Table=ds.Tables["tree"]; dv.RowFilter="ParentId='" + parentId + "'" ; foreach(DataRowView drv in dv) { tmpNd=new TreeNode(); tmpNd.Tag=drv["NodeId"].ToString(); tmpNd.Text=drv["NodeName"].ToString(); Nds.Add(tmpNd); intId=drv["ParentId"].ToString(); InitTree(tmpNd.Nodes,tmpNd.Tag.ToString()); } } //新增节点操作 private void insert(string type) {//判断是新增树节点,还是子节点. string strinsert="insert into s_menu values('{0}','{1}','{2}')"; string strformat=""; if(type=="sub") strformat=string.Format(strinsert,maxnodeid.ToString(),this.selectnode.Tag.ToString(),this.strcomm); else ......余下全文>>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询