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.

See also  How to Avoid Money Transfer Scams  
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist