Page 1 of 1

Insertar/Modificar registros en ACCESS

Posted: Tue Dec 03, 2019 10:58 am
by juanjogascem
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 )

Re: Insertar/Modificar registros en ACCESS

Posted: Wed Dec 04, 2019 2:21 pm
by Euclides
+1
Saludos

Re: Insertar/Modificar registros en ACCESS

Posted: Wed Dec 04, 2019 2:54 pm
by xmanuel
Con HDO directamente o con HDORDD se puede hacer sin problemas...
:D

Re: Insertar/Modificar registros en ACCESS

Posted: Wed Dec 04, 2019 4:58 pm
by nageswaragunupudi
xmanuel wrote:Con HDO directamente o con HDORDD se puede hacer sin problemas...
:D
Isn't HDO based on ADO?

Re: Insertar/Modificar registros en ACCESS

Posted: Wed Dec 04, 2019 5:17 pm
by nageswaragunupudi
Please see your code

Code: Select all

oRs := FW_OpenRecordSet( oDg, "Marcas", adLockBatchOptimistic )
 
If you change it as

Code: Select all

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: Select all

oWnd:bPostEnd := { || oRs:Close() }
 
as

Code: Select all

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.

Re: Insertar/Modificar registros en ACCESS

Posted: Wed Dec 04, 2019 9:37 pm
by juanjogascem
Perfectamente explicado y entendido

Muchas Gracias.