VB6 ADODB.Recordset RecordCount property always returns -1

前端 未结 12 1800
别跟我提以往
别跟我提以往 2020-12-11 15:43

I am trying to get some old VB6 code to work with SQL Server Compact.

I can connect, open the database and all seems well. I can run insert select commands which

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 16:31

    This following code returns the recortcount exactly...

    Public Sub test()
        Dim cn As New ADODB.Connection()
        Dim sPath As String = Application.ExecutablePath
        sPath = System.IO.Path.GetDirectoryName(sPath)
    
        If sPath.EndsWith("\bin") Then
            sPath = sPath.Substring(0, Len(sPath) - 4)
        End If
    
        Dim DbConnectionString As String
        DbConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & sPath & "\students.mdb"
    
        cn.ConnectionString = DbConnectionString
        cn.Open()
    
        Dim rs As New ADODB.Recordset()
        rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rs.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        rs.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
        rs.Open("select * from students", cn)
        MsgBox(rs.RecordCount)
    
        rs.ActiveConnection = Nothing
        cn.Close()
    End Sub
    

提交回复
热议问题