devxlogo

RecordCount Property-ADO

RecordCount Property-ADO

Question:
How do I get the rowseffected from the execute method of an ADO command object?The code I’ve written is:

Dim Cn as New ADODB.ConnectionDim Cmd as New ADODB.CommandDim Recordset as New ADODB.RecordsetDim lintRecEffected As IntegerCn.Open "some connection string"Cmd.ActiveConnection =CnCmd.CommandType=adCmdStoredProcCmd.CommandText = "SelecRecords:        Set Rs=lcmd.ExecutelintRecEffected)msgbox lintreceffected

This shows -1 even though the record is inserted. By the way, my backend is db2.

Answer:
The most important things to remember when working with ADO recordsets are the CursorType, CursorLocation, and LockType properties. In your code, you left these properties as the default settings:

CursorType = ForwardOnlyLockType = ReadOnlyCursorLocation = Server

The ForwardOnly cursor does not retrieve all of the records until they are need. It fetches them each time you call one of the Move methods. Therefore, ADO has no idea how many records will be returned from the recordset and returns a -1 for the recordcount. You will need to use one of the other CursorTypes in order to use the RecordCount property.

devx-admin

Share the Post: