mdb: contains data, but recordcount() answers -1

mdb: contains data, but recordcount() answers -1

Postby gkuhnert » Thu Sep 25, 2008 7:31 pm

Hi,

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

Code: Select all  Expand view
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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: mdb: contains data, but recordcount() answers -1

Postby Enrico Maria Giordano » Thu Sep 25, 2008 9:52 pm

Try

Code: Select all  Expand view
oRecordSet:Open( "SELECT * FROM Name", oConnection, 1, 3 )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby gkuhnert » Fri Sep 26, 2008 6: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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Postby Enrico Maria Giordano » Fri Sep 26, 2008 7:28 am

Try one of the following values for the third parameter:

Code: Select all  Expand view
#define adOpenForwardOnly 0
#define adOpenKeyset      1
#define adOpenDynamic     2
#define adOpenStatic      3


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Enrico Maria Giordano » Fri Sep 26, 2008 7:30 am

And as the last resort try

Code: Select all  Expand view
oRs:CursorLocation = adUseServer


or

Code: Select all  Expand view
oRs:CursorLocation = adUseClient


where

Code: Select all  Expand view
#define adUseServer 2
#define adUseClient 3


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Postby gkuhnert » Fri Sep 26, 2008 2: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
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Postby Enrico Maria Giordano » Fri Sep 26, 2008 3: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:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 56 guests