OLE objects and byref parameters to OLE functions

Dim adodbConnection As New OLEObject( "ADODB.Connection" )

// set up and connect code that works removed as its not relevant

Dim adodbCommand As New OLEObject( "ADODB.Command" )
adodbCommand.ActiveConnection = adodbConnection
adodbCommand.CommandText = "Select * from Testing.dbo.Table_1" // this table has 6 rows in it
Dim recordsaffected As Integer
adodbRecordSet = adodbCommand.Execute(recordsaffected)

Execute normally takes a byref param for the number of rows affected
but regardless of what sql I run (insert select update etc) the byref is never updated

the docs arent clear to me why this might be

Its not clear exactly what this is saying

Is it simply not possible to use a simple type like an integer with a byref like this ?

It sounds like to me, it’s saying that even though you want to use ByRef - it is not possible via the Xojo OLEObject and that any records affected parameter will be treated as a value-type, not a reference-type.

But of course I could be wrong, I haven’t played in this part of Xojo yet.

Good luck.

thats what it does sound like

would be nice if someone from Xojo would comment
@William Yu maybe ?

tried a computed property as well for that parameter and no difference
the setter is never called

crap … cant even introspect the object to see what might work … ARG !!! (uments) :stuck_out_tongue:

[quote]RecordsAffected
Optional. A Long variable to which the provider returns the number of records that the operation affected. The RecordsAffected parameter applies only for action queries or stored procedures. [/quote]

I suspect it will only work with update, append and delete, not a select

I think you need to use the RecordCount property to get that info.

It doesnt work with anything - not update insert delete select

I’ve tried them all

turns out the answer is not obvious or very well documented

you have to use an OLEParameter - NOT a raw XOJO value

you only need to set the value, apparently, for the OLEParameter when you need to pass values IN or BYREF and the function being clled needs that value to work
I could be wrong (the docs are not clear on this)

adodbCommand.ActiveConnection = adodbConnection
adodbCommand.CommandText = SQL

Dim adodbRecordSet As OleObject
Dim rowsaffected As Integer

Dim param As New OLEParameter
param.Type = OLEParameter.ParamTypeSignedLong
param.PassByref = True
param.Position = 1

// execute the update
adodbRecordSet = adodbCommand.execute(param)

rowsaffected = param.value

Thanks to @William Yu for an email reply pointing out the use of OLEParameter