Insertar/Modificar registros en ACCESS

Post Reply
juanjogascem
Posts: 78
Joined: Wed May 31, 2006 8:49 am

Insertar/Modificar registros en ACCESS

Post 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 )
User avatar
Euclides
Posts: 144
Joined: Wed Mar 28, 2007 1:19 pm

Re: Insertar/Modificar registros en ACCESS

Post by Euclides »

+1
Saludos
xmanuel
Posts: 613
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla
Contact:

Re: Insertar/Modificar registros en ACCESS

Post by xmanuel »

Con HDO directamente o con HDORDD se puede hacer sin problemas...
:D
______________________________________________________________________________
Sevilla - Andalucía
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Insertar/Modificar registros en ACCESS

Post by nageswaragunupudi »

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: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Insertar/Modificar registros en ACCESS

Post 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.
Regards

G. N. Rao.
Hyderabad, India
juanjogascem
Posts: 78
Joined: Wed May 31, 2006 8:49 am

Re: Insertar/Modificar registros en ACCESS

Post by juanjogascem »

Perfectamente explicado y entendido

Muchas Gracias.
Post Reply