注册 登录
编程论坛 VB6论坛

报错求解

lg04405115 发布于 2018-10-24 16:08, 1187 次点击
   Public conn As New ADODB.Connection
   
   Public Rec As New ADODB.Recordset
   
    Dim stRecQL As String
   
    Dim Item As Integer
   
    Dim i, j, k As Integer
   
    Dim nodindex As Node

Private Sub Command1_Click()
Do Until Rec.EOF

 For j = 2 To Rec.Fields.Count - 1

  For i = 1 To Rec.RecordCount
  
       MSHFlexGrid1.TextMatrix(i, 1) = Rnd(1)

    Rec.MoveNext
    Next
    Next
Loop
End Sub

Private Sub Form_Load()

   
   
    With conn
        
        If .State = adStateClosed Then
           
           .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "/产量.mdb;Persist Security Info=False"
           
           .Open

        End If

    End With
   
   
    Set nodindex = TreeView.Nodes.Add(, , "爷", "井号", "K1")
   
    nodindex.Sorted = True
   
    '* -----------------------------------------------------------------
   
   
    Rec.Open "产量", conn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
  

    For i = 0 To Rec.RecordCount - 1

        Set nodindex = TreeView.Nodes.Add("爷", tvwChild, "父" & Rec.Fields("ID"), Rec.Fields("井号"), "K1")

        nodindex.Sorted = True

        Rec.MoveNext

    Next i


    'Rec.Close

    '* -----------------------------------------------------------------
   
   
End Sub


Private Sub TreeView_NodeClick(ByVal Node As MSComctlLib.Node)

Text1.Text = Rec.RecordCount



For k = 1 To TreeView.Nodes.Count

    For i = 2 To Rec.Fields.Count - 1

           MSHFlexGrid1.TextMatrix(0, i - 1) = Rec(i).Name

    Next i

    If TreeView.Nodes(k).Selected Then

        For j = 1 To Rec.RecordCount

            For i = 2 To Rec.Fields.Count - 1

                 MSHFlexGrid1.TextMatrix(j, i - 1) = Rec(i).Value

            Next i

          Rec.MoveNext

        Next j

    End If

Next k


End Sub
只有本站会员才能查看附件,请 登录
2 回复
#2
lg044051152018-10-24 16:16
Private Sub TreeView_NodeClick(ByVal Node As MSComctlLib.Node)

Text1.Text = Rec.RecordCount

Do While Not Rec.EOF

For k = 1 To TreeView.Nodes.Count

    For i = 2 To Rec.Fields.Count - 1

           MSHFlexGrid1.TextMatrix(0, i - 1) = Rec(i).Name

    Next i

    If TreeView.Nodes(k).Selected Then

        For j = 1 To Rec.RecordCount

            For i = 2 To Rec.Fields.Count - 1

                 MSHFlexGrid1.TextMatrix(j, i - 1) = Rec(i).Value

            Next i

        Rec.MoveNext

        Next j

    End If

Next k

Loop

添加了Do While Not Rec.EOF,为什么直接跳过了,不执行中间的语句,
只有本站会员才能查看附件,请 登录
#3
ZHRXJR2018-10-25 10:17
Rec.Open "产量", conn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
真搞不懂你的这个语句,不是打开记录集的标准语句,好好看看SQL语言中关于SQL打开记录集的连接代码吧!
Rec.Open "Select * From 产量", conn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
参数 adOpenKeyset, adLockOptimistic, adCmdTableDirect 是游标打开类型的常量,不过我喜欢使用常量数字表示,例如:
Rec.Open "Select * From 产量", conn, 2, 2
1