sql >> Database teknologi >  >> RDS >> Sqlserver

VB6 ADODB.Recordset RecordCount-egenskaben returnerer altid -1

Faktisk CursorLocation spiller en stor rolle i denne sag. Brug rs.CursorLocation = adUseClient for at indstille markørens placering og prøv.

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    Dim DbConnectionString As String

    DbConnectionString = mSqlProvider & _
                            mSqlHost


    Set mDbConnection = New ADODB.Connection
    mDbConnection.CursorLocation = adUseServer

    Call mDbConnection.Open(DbConnectionString)

    If mDbConnection.State = adStateOpen Then
        Debug.Print (" Database is open")
        ' Initialise the command object
        Set mCmd = New ADODB.Command
        mCmd.ActiveConnection = mDbConnection

        mCmd.CommandText = "select * from myTestTable"
        mCmd.CommandType = adCmdText

        Set rs = mCmd.Execute

        Debug.Print rs.RecordCount  ' This should now return the right value.
        Debug.Print rs.Fields(0)   ' returns correct data for first row, first col
        Debug.Print rs.Fields(1)   ' returns correct data for first row, 2nd col
        Debug.Print rs.Fields(2)   ' returns correct data for first row, 3rd col

    End If

End Sub


  1. Oracle-forespørgselsstreng inklusive bindestreg

  2. Få produkt min_pris af sku

  3. MySQL Workbench:hvordan viser man advarsler?

  4. Bedste måde at lære PostgreSQL-lagrede procedurer på?