How to modify data before TMSQuery.Apply/Commit

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Lithium™
Posts: 42
Joined: Wed 23 Jun 2010 06:42

How to modify data before TMSQuery.Apply/Commit

Post by Lithium™ » Mon 24 Oct 2011 07:58

Hello!

Is there any way to modify data in dataset, before Commit(Apply)Updates initiated?

I try use BeforeUpdateExecute(). But all data modifications in this handler are not commited in current commit :( . BeforeUpdateExecute intended for Params sets, it's written in help.

AndreyZ

Post by AndreyZ » Mon 24 Oct 2011 13:18

You can modify a dataset in the BeforeUpdateExecute event handler, but instead of modifying dataset itself, you should modify parameters of an update query. Here is an example:

Code: Select all

procedure TMainForm.BitBtnClick(Sender: TObject);
begin
  MSQuery.SQL.Text := 'select * from emp';
  MSQuery.Open;
  MSQuery.Connection.StartTransaction;
  MSQuery.Edit;
  MSQuery.FieldByName('sal').AsFloat := 700;
  MSQuery.Post;
  MSQuery.Connection.Commit;
end;

procedure TMainForm.MSQueryBeforeUpdateExecute(Sender: TCustomMSDataSet;
  StatementTypes: TStatementTypes; Params: TMSParams);
begin
  if stUpdate in StatementTypes then
    Params.ParamByName('sal').AsFloat := 900;
end;

Lithium™
Posts: 42
Joined: Wed 23 Jun 2010 06:42

Post by Lithium™ » Tue 25 Oct 2011 05:36

Thanks, it works! :) (it seems, I forget this way)

AndreyZ

Post by AndreyZ » Tue 25 Oct 2011 07:19

Feel free to contact us if you have any further questions about SDAC.

Post Reply