Insertar/Modificar registros en ACCESS

Insertar/Modificar registros en ACCESS

Postby juanjogascem » 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 )
juanjogascem
 
Posts: 97
Joined: Wed May 31, 2006 8:49 am

Re: Insertar/Modificar registros en ACCESS

Postby Euclides » Wed Dec 04, 2019 2:21 pm

+1
Saludos
User avatar
Euclides
 
Posts: 154
Joined: Wed Mar 28, 2007 1:19 pm

Re: Insertar/Modificar registros en ACCESS

Postby xmanuel » Wed Dec 04, 2019 2:54 pm

Con HDO directamente o con HDORDD se puede hacer sin problemas...
:D
______________________________________________________________________________
Sevilla - Andalucía
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: Insertar/Modificar registros en ACCESS

Postby nageswaragunupudi » Wed Dec 04, 2019 4:58 pm

xmanuel wrote:Con HDO directamente o con HDORDD se puede hacer sin problemas...
:D

Isn't HDO based on ADO?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10254
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Insertar/Modificar registros en ACCESS

Postby nageswaragunupudi » Wed Dec 04, 2019 5:17 pm

Please see your code
Code: Select all  Expand view

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


If you change it as
Code: Select all  Expand view

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  Expand view

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

as
Code: Select all  Expand view

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

Re: Insertar/Modificar registros en ACCESS

Postby juanjogascem » Wed Dec 04, 2019 9:37 pm

Perfectamente explicado y entendido

Muchas Gracias.
juanjogascem
 
Posts: 97
Joined: Wed May 31, 2006 8:49 am


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 8 guests