1.服务器端的recordset方可使用recordcount

解决方案 »

  1.   

    Dim lStr As String
      Dim cn As ADODB.Connection
      Dim rs As ADODB.Recordset
      Dim fso As Scripting.FileSystemObject
      Dim fExport As TextStream
      Dim strLine As String
      
      If Trim(txtText.Text) = "" Then
        MsgBox "ÇëÖ¸¶¨µ¼³öÎļþ", , "TOEIC"
        cmdDialog.SetFocus
        Exit Sub
      End If
      
      If Dir(txtText.Text) <> "" Then
        MsgBox "&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ouml;&cedil;&para;¨&Ograve;&raquo;&cedil;&ouml;&ETH;&Acirc;&micro;&Auml;&micro;&frac14;&sup3;&ouml;&Icirc;&Auml;&frac14;&thorn;", , "TOEIC"
        cmdDialog.SetFocus
        Exit Sub
      End If
      
      lStr = GetSelect(iChoice)
      If lStr = "" Then Exit Sub
      
      On Error GoTo ErrorHandle1
      
      Set cn = New ADODB.Connection
      Set rs = New ADODB.Recordset
      
      cn.Open gstrConnect
      rs.CursorLocation = adUseClient
      rs.Open lStr, cn, adOpenKeyset, adLockBatchOptimistic
      
      lblNum1.Caption = Trim(Str(rs.RecordCount))
      If rs.RecordCount = 0 Then GoTo ErrorHandle1
      
      Set fso = New Scripting.FileSystemObject
      Set fExport = fso.CreateTextFile(txtText.Text, True, False)
      
      rs.MoveFirst
      Do While Not rs.EOF
        With rs
          strLine = Trim(.Fields("guid")) & Chr(9) & _
            Trim(.Fields("cardid")) & Chr(9) & _
            .Fields("listenscore") & Chr(9) & _
            .Fields("readscore") & Chr(9) & _
            .Fields("totalscore")
          fExport.WriteLine strLine
          
          lblNum2.Caption = Trim(Str(Val(lblNum2.Caption) + 1))
          
          DoEvents
        End With
        rs.MoveNext
      Loop
    ErrorHandle2:
      On Error Resume Next
      fExport.Close
      Set fExport = Nothing
      Set fso = Nothing
    ErrorHandle1:
      If Err.Number <> 0 Then MsgBox Err.Description, , "TOEIC"
      On Error Resume Next
      rs.Close
      cn.Close
      Set rs = Nothing
      Set cn = Nothing
    End SubPrivate Sub Form_Load()
      Call InitDbf
      iChoice = 0
    End Sub
    Private Sub OptScore_Click(Index As Integer)
      cboExam.Visible = IIf(Index = 1, True, False)
      cboSchool.Visible = IIf(Index = 2, True, False)
      cboRoom.Visible = IIf(Index = 3, True, False)
      txtCardID.Visible = IIf(Index = 4, True, False)
      txtRegisterID.Visible = IIf(Index = 5, True, False)
      iChoice = Index
    End SubPublic Sub InitDbf()
      Dim cn As New ADODB.Connection
      
      On Error GoTo ErrorHandle
      
      cn.Open gstrConnect
      
      Set rsExam = New ADODB.Recordset
      rsExam.CursorLocation = adUseClient
      rsExam.Open "select examid,examcity + '  ' + convert(char(10),examdate,126) AS examinfo from te_exam", _
            cn, adOpenStatic, adLockReadOnly
      Set rsExam.ActiveConnection = Nothing
      
      Set cboExam.RowSource = rsExam
      cboExam.ListField = "examinfo"
      cboExam.BoundColumn = "examid"
      
      Set rsSchool = New ADODB.Recordset
      rsSchool.CursorLocation = adUseClient
      rsSchool.Open "select schoolid,schoolid + ' ' + schoolname as schoolinfo from te_school", cn, adOpenStatic, adLockReadOnly
      Set rsSchool.ActiveConnection = Nothing
      
      Set cboSchool.RowSource = rsSchool
      cboSchool.ListField = "schoolinfo"
      cboSchool.BoundColumn = "schoolid"
        
      Dim lStr As String
      Dim cn As ADODB.Connection
      Dim rs As ADODB.Recordset
      Dim fso As Scripting.FileSystemObject
      Dim fExport As TextStream
      Dim strLine As String
      Dim i AS integer  On Error GoTo ErrorHandle1
      
      Set cn = New ADODB.Connection
      Set rs = New ADODB.Recordset
      
      cn.Open gstrConnect
      rs.CursorLocation = adUseClient
      rs.Open "select * from te_score", cn, adOpenKeyset, adLockBatchOptimistic
      
      lblNum1.Caption = Trim(Str(rs.RecordCount))
      If rs.RecordCount = 0 Then GoTo ErrorHandle1
      
      Set fso = New Scripting.FileSystemObject
      Set fExport = fso.CreateTextFile("c:\export.dat", True, False)
      
      rs.MoveFirst
      i = 0
      Do While Not rs.EOF
        i = i + 1
        if i = 10
          fExport.WriteLine rs!A
          i = 0
        else
          fExport.Write rs!A
          i = i + 1
        end if 
        rs.MoveNext
      Loop
    ErrorHandle2:
      On Error Resume Next
      fExport.Close
      Set fExport = Nothing
      Set fso = Nothing
    ErrorHandle1:
      If Err.Number <> 0 Then MsgBox Err.Description, , "TOEIC"
      On Error Resume Next
      rs.Close
      cn.Close
      Set rs = Nothing
      Set cn = Nothing
      

  2.   

    Dim lStr As String
      Dim cn As ADODB.Connection
      Dim rs As ADODB.Recordset
      Dim fso As Scripting.FileSystemObject
      Dim fExport As TextStream
      Dim strLine As String
      Dim i AS integer  On Error GoTo ErrorHandle1
      
      Set cn = New ADODB.Connection
      Set rs = New ADODB.Recordset
      
      cn.Open gstrConnect
      rs.CursorLocation = adUseClient
      rs.Open "select * from te_score", cn, adOpenKeyset, adLockBatchOptimistic
      
      lblNum1.Caption = Trim(Str(rs.RecordCount))
      If rs.RecordCount = 0 Then GoTo ErrorHandle1
      
      Set fso = New Scripting.FileSystemObject
      Set fExport = fso.CreateTextFile("c:\export.dat", True, False)
      
      rs.MoveFirst
      i = 0
      Do While Not rs.EOF
        i = i + 1
        if i = 10
          fExport.WriteLine rs!A
          i = 0
        else
          fExport.Write rs!A
          i = i + 1
        end if 
        rs.MoveNext
      Loop
    ErrorHandle2:
      On Error Resume Next
      fExport.Close
      Set fExport = Nothing
      Set fso = Nothing
    ErrorHandle1:
      If Err.Number <> 0 Then MsgBox Err.Description, , "TOEIC"
      On Error Resume Next
      rs.Close
      cn.Close
      Set rs = Nothing
      Set cn = Nothing