FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour ADO con MySQL problema con listbox
Posts: 185
Joined: Thu Nov 17, 2005 12:48 AM
ADO con MySQL problema con listbox
Posted: Mon Aug 15, 2011 12:14 AM
Mi problema es que al cargar el recordset, el listbox no muestra nada y el RecordCount muestra -1 :-)

gracias de antemano por cualquier ayuda :-)
saludos y
xhabrazos
Code (fw): Select all Collapse
oCon := TOLEAUTO():new("adodb.connection")
oCon:ConnectionString:="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=ERP;User='root'; Password='root';Option=3;"
TRY
  oCon:Open()
  MSGINFO("CONECTADO")
CATCH
    MSGSTOP("NO SE CONECTO")
END
oCmd := TOLEAUTO():New("adodb.command")
oCmd :ActiveConnection(oCon)
oCmd :CommandText := "SELECT * FROM articulos ORDER BY descripcion"

oRs := TOleAuto():New("adodb.recordset")
oRS :CursorLocation := adUseClient
oRS :LockType   := adLockOptimistic
oRS :CursorType := adOpenKeyset
oRs := oCmd:Execute()

DEFINE DIALOG ODLG resource "ODLG_MANART" TITLE "  TABLA DE ARTICULOS "

 oRs:MoveFirst()
? oRs:RecordCount  //  me muestra -1
? oRs:Fields("codigo"):value+" "+ oRs:Fields("descripcion"):value // me muestra bien los datos del primer registro
REDEFINE LISTBOX oLbx FIELDS oRs:Fields("codigo"):value,;
                                                      oRs:Fields("descripcion"):value;
                                             HEADERS "Código",;
                                                      "Descripcion";
                                            id 135 of Odlg                                                                                          
oLbx:aJustify := {.F.,.f.,.t.,.t.}
Luis Alfonso Fuentes Guerrero

FWH 11.06 xHarbour 1.2.1 BCC55 WorkShop
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: ADO con MySQL problema con listbox
Posted: Tue Aug 16, 2011 03:25 PM
Luis

Here is an example of some MS Sql code using ADO with a redefine listbox .. Look at the codeblocks and the Skipper function ..

Rick Lipkin

Code (fw): Select all Collapse
... open tables

IF oRs1:eof
   oRs1:Close()
   return(.f.)
ENDIF

oRs1:MoveFirst()

DEFINE DIALOG oDlg RESOURCE "DISTSLCT"                           ;
       COLOR "W+/W"                                              ;
       TITLE "DISTRICT Select"                                   ;

   REDEFINE LISTBOX oLBX FIELDS          ;
       oRs1:Fields("DISTRICT"):Value     ;
     SIZES 150                           ;
     HEADERS "District"                  ;
     ID 111 of oDlg

   REDEFINE BUTTON oBTN1 ID 113              ;
       ACTION ( zDISTRICT := oRs1:Fields("district"):Value,;
                oOBJ:Refresh(),              ;
                oDlg:END() )                 ;
       DEFAULT


   REDEFINE BUTTON oBTN2 ID 112             ;
       ACTION ( oDLG:END() )

    oLbx:bLogicLen := { || oRs1:RecordCount }
    oLbx:bGoTop    := { || oRs1:MoveFirst() }
    oLbx:bGoBottom := { || oRs1:MoveLast() }
    oLbx:bSkip     := { | nSkip | Skipper( oRs1, nSkip ) }
    oLbx:cAlias    := "ARRAY"


ACTIVATE DIALOG oDlg

oRs1:Close()

oDLG  := NIL
oLBX  := NIL

RETURN( .T. )

//-------------------------------
STATIC FUNCTION SKIPPER( oRsx, nSkip )

LOCAL nRec := oRsx:AbsolutePosition

oRsx:Move( nSkip )

IF oRsx:EOF; oRsx:MoveLast(); ENDIF
IF oRsx:BOF; oRsx:MoveFirst(); ENDIF

RETURN( oRsx:AbsolutePosition - nRec )
Posts: 185
Joined: Thu Nov 17, 2005 12:48 AM
Re: ADO con MySQL problema con listbox
Posted: Tue Aug 16, 2011 05:29 PM
Thanks for your help Rick, I did it as you said in your example but it did't work, besides the function oRs:MoveLast() is not working, the program display the folowing error when it is executed.

Application
===========
Path and name: c:\sistemas\sofvenxh\sofvenxh.Exe (32 bits)
Size: 3,429,888 bytes
Time from start: 0 hours 0 mins 10 secs
Error occurred at: 16/08/2011, 13:26:53
Error description: Error adodb.command:EXECUTE/6 DISP_E_UNKNOWNNAME: MOVELAST
Args:


Regards

Code (fw): Select all Collapse
     oCmd := TOLEAUTO():New("adodb.command")
     oCmd :ActiveConnection(oCon)
   oCmd :CommandText := "SELECT * FROM articulos "                     //ORDER BY descripcion

     oRS := TOleAuto():New("adodb.recordset")
     oRS :CursorLocation := adUseClient          //  EL RECORSET ESTA AL LADO DEL CLIENTE Y NO EN EN EL SERVER
     oRS :LockType   := adLockOptimistic
     //oRS :CursorType := adOpenKeyset
   oRS := oCmd:Execute() // here the error appears

     oRs:MoveLast()
Luis Alfonso Fuentes Guerrero

FWH 11.06 xHarbour 1.2.1 BCC55 WorkShop
Posts: 185
Joined: Thu Nov 17, 2005 12:48 AM
Re: ADO con MySQL problema con listbox
Posted: Wed Aug 17, 2011 12:20 AM
problema solucionado !!
Code (fw): Select all Collapse
   oCon := TOLEAUTO():new("adodb.connection")
   oCon:ConnectionString:="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=ERP;User='root'; Password='root';Option=3;"
     TRY
       oCon:Open()
     MSGINFO("CONECTADO")
     CATCH
        MSGSTOP("NO SE CONECTO")
     END
     oCmd := TOLEAUTO():New("adodb.command")
     oCmd :ActiveConnection(oCon)
   //oCmd :CommandText := "SELECT * FROM articulos ORDER BY descripcion"     esto no funcionaba y oRS := oCmd:Execute()
     oRS := TOleAuto():New("adodb.recordset")                                 //comentado mas abajo
     oRS :CursorLocation := adUseClient
     oRS :LockType   := adLockOptimistic
     oRS :CursorType := adOpenKeyset
   //oRS := oCmd:Execute()
   oRs:activeconnection(oCon)                                   // con estas 3 lineas
     oRs:source := "SELECT * FROM articulos ORDER BY descripcion" // funcionó
     oRS:open()                                                   // perfecto
Luis Alfonso Fuentes Guerrero

FWH 11.06 xHarbour 1.2.1 BCC55 WorkShop

Continue the discussion