Strict Update

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ninken
Posts: 8
Joined: Thu 05 Apr 2007 18:31
Location: USA

Strict Update

Post by ninken » Thu 05 Apr 2007 18:36

I want to have strict updates enabled, but I want to trap the error message and do something. Is this possible? If not can I make a request for event OnStrictupdateError!

Thanks

Ken

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 06 Apr 2007 12:05

You can use try..except statements to catch strict update exceptions:

Code: Select all

try
  MSQuery1.Edit;
  MSQuery1.FieldByName('SomeFieldName').AsString := 'some value';
  MSQuery1.Post;
except
  on E: EDatabaseError do
    //Check the MSQuery1.RowsAffected property
end;

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 06 Apr 2007 14:29

You can also set the TMSQuery.Options.StrictUpdate property to False and check the TMSQuery.RowsAffected property value in the TDataSet.AfterPost event.
The most proper way, in our opinion, is to add an unique primary key field to the table. It will guarantee that updates will affect only one record.

Post Reply