How do I call SQLRowCount from Delphi or ActiveX Data Objects (ADO)?

To call SQLRowCount from Delphi:

function SQLRowCount(hstmt:LongInt;var RowCount:LongInt):SmallInt;stdcall;external 'ODBC32.DLL';

To call SQLRowCount from ADO:

METHOD: Command::Execute
Syntax for non-row-returning:

commandobject.Execute RecordsAffected, Parameters, Options
              
Syntax for row-returning:
              
Set recordsetobject = commandobject.Execute (RecordsAffected, Parameters, Options)

The Execute method returns a reference to a Recordset object. You use this method to execute the query, SQL statement, or stored procedure contained in the CommandText property of the Command object. If it's a row-returning query, the results are stored in a new Recordset object. If it's not a row-returning query, the provider returns a closed Recordset object.

There are three optional parameters.

  • The RecordsAffected parameter is a long value returned by the provider and is the number of records affected by an action query. (For a row-returning query, use the RecordCount property of the Recordset object to get a count of how many records are in the object.)
  • The Parameters parameter updates or inserts new parameter values into the Parameters collection assigned to the Command object.
  • The Options parameter defines how the provider should evaluate the CommandText parameter. It's a long value that is the sum of one or more of the CommandTypeEnum or ExecuteOptionEnum constants. The default is adCmdUnspecified or -1.