如果你的tid字段是数字类型的,那么下面这句有错误
Set List = conn.Execute("select * from books where tid=" & rs("id") & "")改成
Set List = conn.Execute("select * from books where tid=" & rs("id"))

解决方案 »

  1.   

    错误依旧,和读取数据库没什么关系的样子,是treeview的问题
      

  2.   

    tv1.Nodes.Add rs("tname"), tvwChild, List("title"), List("title")
    改成不用List作为ADODB.Recordset,换一个名字,例如ListItems
    opdb
    dim ListItems as ADODB.Recordset
    set ListItems = new ADODB.RecordsetSet rs = conn.Execute("select * from type")
    If Not rs.EOF Then
    While Not rs.EOF
       tv1.Nodes.Add , , rs("tname"), rs("tname")
       Set ListItems = conn.Execute("select * from books where tid=" & rs("id"))
       If Not ListItems.EOF Then
        While Not ListItems.EOF
            tv1.Nodes.Add rs("tname"), tvwChild, ListItems("title"), ListItems("title")
            ListItems.MoveNext
        Wend
       Else
        tv1.Nodes.Add rs("tname"), tvwChild, "error", "没有资料卡片"
       End If
       ListItems.Close
       Set ListItems = Nothing
       rs.MoveNext
    Wend
    Else
        tv1.Nodes.Add , , "error", "没有分类"
    End If
      

  3.   

    哈哈…………我一看就知道你错在那里了
    要知道List是控件名字,你用了set List = xxx当然错了,将List改为别的名字就没有错了,就算错,也是你的程序本身有错了。
      

  4.   

    LISTITEMS也是系统保留字呀,你就不能用个什么RSlist作为recordset的名字吗?要知道,养成良好的命名习惯也是很重要的呀,Recordset尽量就是rs作为对象,listitems是listview等多种控件的对象集合,你这样当然会对错了
      

  5.   

    LISTITEMS也是系统保留字呀,你就不能用个什么RSlist作为recordset的名字吗?要知道,养成良好的命名习惯也是很重要的呀,Recordset尽量就将rs作为前缀,listitems是listview等多种控件的对象集合,你这样当然会对错了
      

  6.   

    try: tv1.Nodes.Add "" & rs("tname"), tvwChild, "" & List("title"), "" & List("title")
      

  7.   

    唉,我用listbox可以正确运行的嘛,数据库操作是没错的,list 和listitem都不沾边,关键是treeview的操作问题,在双重循环中relation的参数用key怎么都会出错,但使用index就没有问题了,我用index调试成功了,但是想知道为什么不能用key
    下面是用index调试成功的代码:
    Set rs = conn.Execute("select * from type")
    i = 1
    If Not rs.EOF Then
    While Not rs.EOF
       tv1.Nodes.Add , 1, , rs("tname")
       Set ListItem = conn.Execute("select * from books where tid=" & rs("id"))
        r = i
        While Not ListItem.EOF
            tv1.Nodes.Add i, 4, ListItem("title"), ListItem("title")
            ListItem.MoveNext
        r = r + 1
        Wend
        i = r
       ListItem.Close
       Set ListItem = Nothing
       rs.MoveNext
       i = i + 1
    Wend
    Else
        tv1.Nodes.Add , 1, , "没有分类"
    End If
      

  8.   

    TreeView.Nodes.Clear
    TreeView.Refresh
    Dim I As Integer
    Dim j As Integer    For I = 1 To 6
            TreeImages.ListImages.Add , , TreeImage(I).Picture '增加图片
        Next I
        TreeView.ImageList = TreeImages
        Set factory = TreeView.Nodes.Add(, , "f 总公司", "总公司", 1, 4) '设置总公司
        factory.Expanded = True
        Set Rs = New ADODB.Recordset
        strSQL = "select distinct Department from BaseInfo"
        Rs.Open strSQL, Conn, adOpenDynamic, adLockBatchOptimistic
        With Rs
        If Not .EOF And Not .BOF Then
            DepCount = .RecordCount
            Do While Not .EOF
                Set group = TreeView.Nodes.Add(factory, tvwChild, j & .Fields(0).value, .Fields(0).value, 2, 4)
                depName(j) = .Fields(0).value
                j = j + 1
                .MoveNext
            Loop
        Else
            depName(j) = ""
        End If
        End With
    只作参考
      

  9.   


    Set rs = conn.Execute("select * from type")
    If Not rs.EOF Then
    While Not rs.EOF
       tv1.Nodes.Add , , rs("tname"), rs("tname")
       Set List = conn.Execute("select * from books where tid=" & rs("id") & "")
       If Not List.EOF Then
        While Not List.EOF
            tv1.Nodes.Add rs("tname"), tvwChild, List("title"), List("title")'提示这里出错 ,你的问题可能在结点的key不唯一
            List.MoveNext
        Wend
       Else
        tv1.Nodes.Add rs("tname"), tvwChild, "error", "没有资料卡片" '如果有两种类型的
        书没有资料卡片,key为error的结点会添加两次。
       End If
       List.Close
       Set List = Nothing
       rs.MoveNext
    Wend
    Else
        tv1.Nodes.Add , , "error", "没有分类"
    End If那位帮我看看是怎么回事啊?提示说invaild object
      

  10.   

    更改出错的这一句:
    tv1.Nodes.Add rs("tname"), tvwChild, List("title"), List("title")
    将它改为:
    tv1.Nodes.Add rs("tname").value, tvwChild, List("title"), List("title")
    就行了