I am trying to add a record to access database table but the update does not seem to work.
Regards
Colin
- Code: Select all Expand view
#define EditCode 101
#define BtnExit 102
#define BtnNext 103
#define BtnLast 104
#define EditClient 105
#define BtnAdd 106
#define BtnSave 107
#include "fivewin.ch"
function fnAdd()
local oDlg,lExit := FALSE,oCon,oBtnExit,oBtnNext,oBtnLast,oBtnAdd,oBtnSave,aData := array(1),lNew := FALSE
oCon := fnConnect(oCon)
if ! empty(oCon)
oRs := TOleAuto():new( "ADODB.RecordSet" )
oRs:ActiveConnection := oCon
oRs:Source := "SELECT * FROM code"
oRs:CursorType := 1
oRs:LockType := 4 // adLockOptimistic
oRs:CursorLocation := 3 //adUseClient
oRs:CacheSize := 100
TRY
oRs:Open()
CATCH
MsgInfo('Table Open Failure')
END
DEFINE DIALOG oDlg RESOURCE 'ADD'
REDEFINE GET oCode VAR aData[1] ID EditCode UPDATE picture '@!'
REDEFINE BUTTON oBtnNext ID BtnNext of oDlg ;
ACTION(oRs:MoveNext(),if(oRs:eof(),oRs:MoveLast(),),lfGetRecs(lNew,oRs,aData),oDlg:Update())
REDEFINE BUTTON oBtnAdd ID BtnAdd of oDlg ;
ACTION(lNew := TRUE,lfGetRecs(lNew,oRs,aData),oDlg:Update(),oDlg:aControls[1]:SetFocus())
REDEFINE BUTTON oBtnSave ID BtnSave of oDlg ;
ACTION(lfUpRecs(oRs,aData),oDlg:Update())
REDEFINE BUTTON oBtnLast ID BtnLast of oDlg ;
ACTION(oRs:MovePrevious(),if(oRs:bof(),oRs:MoveFirst(),),lfGetRecs(lNew,oRs,aData),oDlg:Update())
REDEFINE BUTTON oBtnExit ID BtnExit OF oDlg ;
ACTION(lExit := TRUE,oDlg:end())
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT(oRs:MoveFirst(),lfGetRecs(lNew,oRs,aData),oDlg:Update());
VALID(lExit)
else
MsgInfo('Not Connected to Database')
endif
return(nil)
//---------------------------------------------------------------------------------------------------//
static function lfGetRecs(lNew,oRs,aData)
local i := 0
asize(aData,0)
for i := 1 to 1
aadd(aData,if(lNew,space(7),oRs:Fields("code"):Value))
next
return(nil)
//---------------------------------------------------------------------------------------------------//
static function lfUpRecs(oRs,aData)
local i := 0
for i := 1 to len(aData)
oRs:AddNew()
oRs:Fields('code'):value := aData[1]
oRs:Update()
next
return(nil)