Board index » delphi » TDataset.UpdateRecord doesn't work For me?!?

TDataset.UpdateRecord doesn't work For me?!?

Hi,

Maybe I got this wrong but my understanding of the UpdateRecord Procedure is
to allow for the verification of each record before they are posted to the
Database in a TQuery or TTable when Cached Updates is set to True.

Now I have code here that I think would work but it doesn't if you know why
let me know.  There are no Delphi Exemple provided and the Delphi Help is
very limmited.

procedure TDM_TransMonitor.Query1UpdateRecord(
  DataSet: TDataSet; UpdateKind: TUpdateKind;
  var UpdateAction: TUpdateAction);
begin
  If DataSet.FieldByName('RECORDID').AsString = '24'
  Then Begin
    UpdateAction := uaApplied ;
  End
  Else UpdateAction := uaSkip ;
end;

This code goes down the If Then Branch and it doesn't depending on the
condition.  Thsi part works.  What doesn't is that I does nothing!   All the
record yout a RecordID of 24 stays in the Query same as the other record
with a recordID other than 24.

Am I supposed to do something to actually write the data to the Database ?
what Am I doing wrong?

eric
ejod...@inetex.com

 

Re:TDataset.UpdateRecord doesn't work For me?!?


Eric,

Quote
>  If DataSet.FieldByName('RECORDID').AsString = '24'
>  Then Begin
>    UpdateAction := uaApplied ;
>  End
>  Else UpdateAction := uaSkip ;
>end;

The OnUpdateRecord handler is an alternative (and can also be a supplement)
to the TUpdateSQL component.  By that I mean that Delphi will not
automatically post to the database (using the TUpdateSQL component) if you
have code in your OnUpdateRecord handler.  If you need to do some additional
processing (and thus need to put code in the OnUpdateRecord handler) you
will need to explicitly call Apply(UpdateKind), which in turn calls
SetParams and ExecSQL.

-- Mark

Re:TDataset.UpdateRecord doesn't work For me?!?


Assuming that you're getting into the updaterecord event handler, your
code is looking to branch on specific data. Using the AsString property
is not appropriate in updaterecord. When you use parameters in the
Tupdatesql object, it gets the values from the OldValue or NewValue
properties (depending on whether the record is in an inserted or updated
state. Therefore, when you use the dataset parameter, you must use
NewValue or Oldvalue only.

Secondly, as mentioned by another response to your query, you need to
setup the updatesql object in updaterecord and call its apply method.
This actually takes the cached update through to the database. The
Updaterecord event handler allows you to dynamically change what
database activity occurs (when required based on data or control changes
to your program). The Tupdatesql object still does all the work.

Quote
Eric wrote:

> Hi,

> Maybe I got this wrong but my understanding of the UpdateRecord Procedure is
> to allow for the verification of each record before they are posted to the
> Database in a TQuery or TTable when Cached Updates is set to True.

> Now I have code here that I think would work but it doesn't if you know why
> let me know.  There are no Delphi Exemple provided and the Delphi Help is
> very limmited.

> procedure TDM_TransMonitor.Query1UpdateRecord(
>   DataSet: TDataSet; UpdateKind: TUpdateKind;
>   var UpdateAction: TUpdateAction);
> begin
>   If DataSet.FieldByName('RECORDID').AsString = '24'
>   Then Begin
>     UpdateAction := uaApplied ;
>   End
>   Else UpdateAction := uaSkip ;
> end;

> This code goes down the If Then Branch and it doesn't depending on the
> condition.  Thsi part works.  What doesn't is that I does nothing!   All the
> record yout a RecordID of 24 stays in the Query same as the other record
> with a recordID other than 24.

> Am I supposed to do something to actually write the data to the Database ?
> what Am I doing wrong?

> eric
> ejod...@inetex.com

Other Threads