如何在vb.net连接Ms填充树视图访问数据库 [英] how to fill the tree view in vb.net connectivity Ms access database

查看:60
本文介绍了如何在vb.net连接Ms填充树视图访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这个编码来填充树视图



I used this coding to fill the tree view

If (con.State = ConnectionState.Closed) Then
           con.Open()
       End If
       Dim cmd As New OleDbCommand("select Sid,Sname from Subject ", con)
       Dim Sub_subject As New OleDbCommand("select Sub_ID,Sub_Name from Sub_Subject ", con)
       Dim Category As New OleDbCommand("select Cid,Cname from Category ", con)
       Dim Sub_Category As New OleDbCommand("select Sub_Cid,Sub_Cname from Sub_Category", con)
       Dim Fileupload As New OleDbCommand("select Sub_Cid,FileUpload from FileUpload", con)

       Dim dr As OleDbDataReader
       dr = cmd.ExecuteReader
       Dim dr_sub As OleDbDataReader
       dr_sub = Sub_subject.ExecuteReader
       Dim dr_Category As OleDbDataReader
       dr_Category = Category.ExecuteReader
       Dim dr_sub_cat As OleDbDataReader
       dr_sub_cat = Sub_Category.ExecuteReader
       Dim dr_file As OleDbDataReader
       dr_file = Fileupload.ExecuteReader

       While dr.Read() And dr_sub.Read() And dr_Category.Read() And dr_sub_cat.Read()
           TreeView1.Nodes.Add(dr(1).ToString).Nodes.Add(dr_sub(1).ToString).Nodes.Add(dr_Category(1).ToString).Nodes.Add(dr_sub_cat(1).ToString)

       End While
       dr.Close()
       dr_sub.Close()
       dr_Category.Close()
       dr_sub_cat.Close()
       dr_file.Close()
       con.Close()

   Catch ex As Exception

   End Try





任何其他方式来填充数据库中的树视图



any another way to fill the tree view in database

推荐答案

是的,这是可怕的。它充满了糟糕的假设。



你应该根据列表填写最高级别。然后应该使用SQL填充每个子级别以获取该级别的项目,基于父级,第二级甚至是否有ID来标识它在DB中的父级?
Yes, this is horrendous. It is full of bad assumptions.

You should fill the top level based on a list. Then each sub level should be filled using SQL to get the items for that level, based on the parent, Does the second level even have an id to identify it's parent in the DB ?


这篇关于如何在vb.net连接Ms填充树视图访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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