我想将某一字段的值读到treeview中,我用下面的代码,treeview居然没反应,是哪写错了吗?
Dim conn As New adodb.Connection
Dim rs As New adodb.Recordset
Dim key, text, connstr, rsstr As String
connstr = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=e"
rsstr = "select distinct zzmm from temp where zzmm<>''"
conn.Open connstr
rs.Open rsstr, conn
TreeView1.LineStyle = tvwTreeLines 
TreeView1.Style = tvwTreelinesPlusMinusPictureText
If rs.RecordCount > 0 Then
   rs.MoveFirst
   Do While rs.EOF = False
     key = Trim(rs.Fields("zzmm"))
     text = Trim(rs.Fields("zzmm"))
     Set nodx = TreeView1.Nodes.Add(, , key, text)
     
   Loop
End If
TreeView1.Refresh

解决方案 »

  1.   

    Do While rs.EOF = False改成Do While Not Rs.EOF试试
      

  2.   

    不清楚楼上的能不能行,可以试试。建议,用F8单步执行一下看看。
    应该不是treeview的问题,可能是数据库里面没数据~?
      

  3.   

    当Open一个Recordset后,不要立即用Recordset的RecordCount判断记录总数。Do While rs.EOF = False
        ' your code here ...    ' This line is very IMPORTANT
        rs.MoveNext
    Loop
      

  4.   

    哈哈,之前居然没看到。quickball说得对,rs.MoveNext一定要有。
      

  5.   

    前面加个conn.CursorLocation = adUseClient试试
    而且还得加个rs.movenext
      

  6.   

    谢谢,确实是在
    if rs.recordcount>0处就跳过了不过我就不明白为什么不能立即用Recordset的RecordCount判断记录总数。
      

  7.   

    If CursorLocation = adUseClient Then
        You can use RecordCount property
    End If