UpdateStatus is not returning correct value



Hi,

This code was working and suddenly quit. This is in a tADODataset. There is
one record in the recordset.

if qryCandidate.UpdateStatus = usModified then ...

I have a tDBEdit linked to a dataset which is linked to qryCandidate.

If i change a value on the form in the tdbedit, UpdateStatus used to be set
correctly. I could detect it in the
FormCloseQuery event of the form and prompt to save "unsaved" changes. It
suddenly quit working and always shows usUnModified as the status of the
record. I thought at first that I might have changed locktype by accident to
ltOptimistic but it is definitely set at ltBatchOptimistic.

I am running D2007 (no updates), Sql Server 2005, WinXP Pro SP2,

Here is the strange thing.

I wanted to capture "date last updated" and post it in the DB. I added the
code to do so in the FormCloseQuery event ...

if qryCandidate.UpdateStatus = usModified then
if messagedlg('Do you want to save the changes to the Candidate Record
?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
qryCandidate.FieldByName('datelastupdate').asfloat := date();
<<<<< NEW
qryCandidate.updatebatch;
end;

I have a "save" button on the screen. If they hit "save" they may not
actually have changed any data so I didnt want to just force a date into the
record, that would be wrong. So I added code to check to see if the record
was changed. I put the following in the onClick event of the "save" button.
(The part that is now commented out, all the rest was already there).

// if qryCandidate.UpdateStatus = usModified then begin
with qryCandidate do begin
edit;
fieldbyname('datelastupdate').asfloat := date();
post;
UpdateBatch;
end;
// end;


That is when updatestatus quit returning the correct value.

As you can see, I commented it out. The uncommented code now works but
forces a date even though the record may not really have been updated .. all
it means is that someone hit "save", not that the record was acutally
updated..

"updatestatus" always shows usUnModified ..everywhere .. no matter what ..
when I check its value in the debugger. If I change a value on the screen,
hit "save", trap the code in the above snippet, I can test newvalue,
oldvalue and curvalue and they show different, yet UpdateStatus show
usUnModified ...

Anybody have any idea of what the hell is going on ??? This was supposed to
be a 5 minute change and has turned into a 3 day project which I cant
possibly bill the client for ...

Frustrated a the beach ,

Del




.


Quantcast