FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour mdb: contains data, but recordcount() answers -1
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
mdb: contains data, but recordcount() answers -1
Posted: Thu Sep 25, 2008 07:31 PM
Hi,

my small sample access-database contains one table with three fields and four recordsets. To browse it, I use following code:

function browsen()
   local oWin2
   local oConnection := TOleAuto():New( "ADODB.Connection" )
   local oRecordSet
   local oBrw

  DEFINE WINDOW oWin2 MDICHILD FROM 5, 7 TO 17, 40 TITLE "XBrowse"

     oConnection:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=gilbert.mdb; Persist Security Info=False" )

     oRecordSet:=TOleAuto():New( "ADODB.Recordset" )
     oRecordSet:Open( "SELECT * FROM Name", oConnection )

     msginfo(oRecordSet:Fields( "Name" ):Value)    // Here I get a value = "Hans"
     msginfo(oRecordSet:RecordCount())             // Here the response = "-1"
     oBrw:=TXbrowse():New(oWin2)
     oBrw:SetAdo( oRecordSet )

     oBrw:Createfromcode()
     oWin2:SetControl(oBrw)

  ACTIVATE WINDOW oWin2

return .t.


When I call "msginfo(oRecordSet:Fields( "Name" ):Value)" I get "Hans" as an answer, what is the content of Name in the first record. But when I call "msginfo(oRecordSet:RecordCount())" the answer is "-1".
As a consequence, xbrowse does not show any records. I get the same behaviour with mysql-databases.
Can somebody help me?
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: mdb: contains data, but recordcount() answers -1
Posted: Thu Sep 25, 2008 09:52 PM
Try

oRecordSet:Open( "SELECT * FROM Name", oConnection, 1, 3 )


EMG
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 06:22 AM

Enrico,
thank you, with mdb it did the trick.
But with mySql the same problem remains. What is it, that these parameters do? And have I to use other parameters for mySql?

Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 07:28 AM
Try one of the following values for the third parameter:

#define adOpenForwardOnly 0
#define adOpenKeyset      1
#define adOpenDynamic     2
#define adOpenStatic      3


EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 07:30 AM
And as the last resort try

oRs:CursorLocation = adUseServer


or

oRs:CursorLocation = adUseClient


where

#define adUseServer 2
#define adUseClient 3


EMG
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 11:51 AM

RecordCount() works correctly only if CursorLocation is adUseClient.
RecordCount() always returns -1 when the recordset is opened on the server ( i.e., CursorLication = adUseServer)

Regards



G. N. Rao.

Hyderabad, India
Posts: 274
Joined: Fri Apr 04, 2008 01:25 PM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 02:36 PM

NageswaraRao, Enrico,
Thanks a lot, now it works with both types of databases :)

Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
mdb: contains data, but recordcount() answers -1
Posted: Fri Sep 26, 2008 03:34 PM
nageswaragunupudi wrote:RecordCount() works correctly only if CursorLocation is adUseClient.
RecordCount() always returns -1 when the recordset is opened on the server ( i.e., CursorLication = adUseServer)


This is not completely true. The following sample using MSDE work with both CursorLocation:

#define adOpenForwardOnly 0
#define adOpenKeyset      1
#define adOpenDynamic     2
#define adOpenStatic      3

#define adLockReadOnly        1
#define adLockPessimistic     2
#define adLockOptimistic      3
#define adLockBatchOptimistic 4

#define adUseServer 2
#define adUseClient 3


FUNCTION MAIN()

    LOCAL oRs := CREATEOBJECT( "ADODB.Recordset" )

//    oRs:CursorLocation = adUseServer
    oRs:CursorLocation = adUseClient

    oRs:Open( "SELECT * FROM Contatti ORDER BY RagSoc2, RagSoc1", "Provider=SQLOLEDB;Integrated Security=SSPI;Data Source=EMAG\Emag;Initial Catalog=Ecmp", adOpenKeyset, adLockOptimistic )

    ? oRs:RecordCount

    oRs:Close()

    RETURN NIL


EMG

Continue the discussion