包括所有的代码。连接数据库,遍历查找表 ,给TREEVIEW赋值

解决方案 »

  1.   

    将你的数据库结构做一下合理的修改,有“上级类”和“本级分类”;“上级类”用来判断它的上级是什么,“本级分类”用来判断本级分类。代码如下,你琢磨一下!
    TV1.Nodes.Clear
          
            Set MYNOD = TV1.Nodes.Add(, , "root", "AAA", 1, 2)
            Set CNRS = New ADODB.Recordset
            SQL = "select * from GYS_ZL ORDER BY ZLLEV,flm"
            CNRS.Open SQL, CONN, 1, 1
                  
            Do Until CNRS.EOF
              Set MYNOD = TV1.Nodes.Add(CStr(CNRS!上级类), 4, CNRS!本级类, CNRS!编码 & " " & CNRS!名称, 1, 2)
              CNRS.MoveNext
            Loop
            CNRS.Close
            Set CNRS = Nothing
            
            TV1.Nodes(1).Expanded = True
      

  2.   

    在调用数据库的时候我
    cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=ywc;Data Source=CH"
    cn.Open
    Dim roottree As String
    roottree = Text1.Text
    rss.Source = "select hcode from tree where code=" + roottree
    rss.Open                  怎么会出错?说是找不到列名。请告诉我该怎么写好
      

  3.   

    rss.Source = "select hcode from tree where code='"& roottree & "'"