FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Insertar/Modificar registros en ACCESS
Posts: 103
Joined: Wed May 31, 2006 08:49 AM
Insertar/Modificar registros en ACCESS
Posted: Tue Dec 03, 2019 10:58 AM

Buenas, no logro insertar registros en una BD ACCESS, utilizo el siguiente código copiado del ejemplo TESTXBR3.PRG,al cual le paso lo mismo.
el XBROWSE lo refleja correctamente, ALTAS, BAJAS, MODIFICACIONES, pero al salir y volver a entrar veo que en la BD no queda reflejado nada y tampoco da error.
Saben que ocurre?. Alguna solución?

  oRs   := FW_OpenRecordSet( oDg, "Marcas", adLockBatchOptimistic )

  DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12

  DEFINE WINDOW oDlg MDICHILD OF WndMain() TITLE cTitulo

  @ 0,0 XBROWSE oBrw ;
        COLUMNS "cCodMar", "cDesMar" ;
        OF oDlg ;
        RECORDSET oRs ;
        AUTOSORT FOOTERS FASTEDIT LINES CELL


 AEval( oBrw:aCols, { |o| o:cToolTip := { 'Column :' + CRLF + o:cHeader, 'ToolTip' }, ;
                          o:nEditType := EDIT_GET } )

 WITH OBJECT oBrw
    :bPopUp           := { |o| ColMenu( o ) }
    :MakeTotals()
    :CreateFromCode()
 END
 oWnd:oClient      := oBrw
 oWnd:bPostEnd     := { || oRs:Close() }

 BtnBar( oBrw )
Posts: 159
Joined: Wed Mar 28, 2007 01:19 PM
Re: Insertar/Modificar registros en ACCESS
Posted: Wed Dec 04, 2019 02:21 PM

+1
Saludos

Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: Insertar/Modificar registros en ACCESS
Posted: Wed Dec 04, 2019 02:54 PM

Con HDO directamente o con HDORDD se puede hacer sin problemas...

:D

______________________________________________________________________________

Sevilla - Andalucía
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Insertar/Modificar registros en ACCESS
Posted: Wed Dec 04, 2019 04:58 PM
xmanuel wrote:Con HDO directamente o con HDORDD se puede hacer sin problemas...
:-)

Isn't HDO based on ADO?
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Insertar/Modificar registros en ACCESS
Posted: Wed Dec 04, 2019 05:17 PM
Please see your code
Code (fw): Select all Collapse
oRs := FW_OpenRecordSet( oDg, "Marcas", adLockBatchOptimistic )


If you change it as
Code (fw): Select all Collapse
oRs := FW_OpenRecordSet( oDg, "Marcas" )
//OR
oRs := FW_OpenRecordSet( oDg, "Marcas", adLockOptimistic )
// default lockmode is adLockOptimistic

everything works correctly as expected.
First please try it before getting into the next discussion.

If you open the recordset with adLockBatchOtpimistic mode, all changes (modifications, deletions and appends) are written only to the Recordset in our PC's MEMORY ONLY but NOT written to the physical database.

To finally save all the changes at once to the physical database, you need to call oRs:UpdateBatch() or abandon all changes by calling oRs:CancelBatch() or simply closing the recordset by calling oRs:Close()

In the above example, you are closing the RecordSet without saving the changes by calling oRs:UpdateBatch. So all the changes are lost.

In the above example, if you still want to open with adLockBatchOptimistic mode, change this code:

Code (fw): Select all Collapse
oWnd:bPostEnd := { || oRs:Close() }

as
Code (fw): Select all Collapse
oWnd:bPostEnd := { || oRs:UpdateBatch(), oRs:Close() }


With this change, your modifications, deletes and appends are not written to the physical database as and when the user makes them, but all these changes are dumped to the physical database when the MdiChild window is closed.

So
1) If you want to save the changes to the physical database immediately as and when the user edits the browse, you open recordset with default lockmode provided by FWH or specifying adLockOptimistic mode.

OR

2) If you do not want to make the changes during edit but after closing the window, then open the reocordset with "adLockBatchOptimistic" locking and towards the end save all the changes by calling oRs:UpdateBatch() before calling oRs:Close()

Note:
We advise you use the default mode (i.e., adLockOptimistic) till you master ADO and learn to handle resolution of conflicts while calling oRs:UpdateBatch(). This is after you gain mastery over ADO.
Regards



G. N. Rao.

Hyderabad, India
Posts: 103
Joined: Wed May 31, 2006 08:49 AM
Re: Insertar/Modificar registros en ACCESS
Posted: Wed Dec 04, 2019 09:37 PM

Perfectamente explicado y entendido

Muchas Gracias.

Continue the discussion