Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

VB6 ADODB.Recordset RecordCount properti selalu mengembalikan -1

Sebenarnya CursorLocation berperan besar dalam hal ini. Gunakan rs.CursorLocation = adUseClient untuk mengatur lokasi kursor dan mencoba.

    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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara memeriksa apakah ada Kendala di server Sql?

  2. Apa itu Logis DAN Operator di SQL Server - Tutorial SQL Server / TSQL Bagian 120

  3. Cara tercepat untuk menghapus karakter non-numerik dari VARCHAR di SQL Server

  4. SQL Server 2005 - Ekspor tabel secara terprogram (jalankan file .sql untuk membangunnya kembali)

  5. Masukkan Gambar ke dalam Bidang Gambar SQL Server 2005 hanya menggunakan SQL