Re: Preventing Duplicates in BeforePost event.



Now I have a new problem. I got the BeforePost working but now the pending
updates will not post to the database. I have verifed that there are indeed
updates pending, and after a call to UpdateBatch there are no more updates
pending, but the records are not in the database.

If I comment out the code in the BeforePost, then the record are posted to
the database. However, for some reason if the code in the BeforePost is
used then no records will be posted to the database on the UpdateBatch.

One more thing is there anyway to debug the UpdateBatch procedure? I would
like to step through it and see some command is not being executed do to
some status. the only procedure I can step into is the following..

procedure TCustomADODataSet.UpdateBatch(AffectRecords: TAffectRecords);
begin
CheckBrowseMode;
Recordset.UpdateBatch(AffectRecordsValues[AffectRecords]); --- Can I step
into this somehow?
UpdateCursorPos;
Resync([]);
end;

Here is my new and inproved BeforePost...

--------------
procedure TdmTestDelay.dsetAccessionBeforePost(DataSet: TDataSet);
var CloneSet : TADODataSet;
RS : _RecordSet;

procedure CloneIt;
begin
CloneSet.Connection := dmADOConnections.conANSR;
CloneSet.LockType := ltBatchOptimistic;
RS := TADODataSet(DataSet).Recordset.Clone(adLockUnspecified);
RS.Set_ActiveConnection(nil);
CloneSet.Recordset := RS;
end;

begin
if not(DataSet.State in [dsInsert, dsEdit]) then exit;
CloneSet := TADODataSet.Create(nil);
try
if (DataSet.State in [dsInsert]) then
begin
CloneIt;
if
CloneSet.Locate('ACCESSION',DataSet.FieldByName('ACCESSION').AsString,[])
then
begin
MessageDlg(DataSet.FieldByName('ACCESSION').AsString+
' has already been entered.', mtInformation, [mbOK], 0);
Abort;
end;
end else
begin
CloneIt;
if
(CloneSet.Locate('ACCESSION',DataSet.FieldByName('ACCESSION').AsString,[]))
and not(CloneSet.RecNo = DataSet.RecNo) then
begin
MessageDlg(DataSet.FieldByName('ACCESSION').AsString+
' has already been entered.', mtInformation, [mbOK], 0);
Abort;
end;
end;
finally
CloneSet.Close;
CloneSet.Free;
end;
end;
-----------------------






"Brian Bushay TeamB" <BBushay@xxxxxxxxx> wrote in message
news:704rd1993hf8j3jjojl8tqqp6pnou3go4u@xxxxxxxxxx

>This worked great while the user was entering the values. However, if at a
>later time in the code a record had to be modified, the BeforePost event
>would fire and then I would get the message about a dupicate record. This
>is because the cloned dataset now had all entered record and whenever the
>BeforePost event fires it aready has the values.
You should be able to check the STATUS property. If it is dsInsert use
your
code and if it is DSUpdate you need to check for more than one record with
your
key value

>
>Does anyone else know of a better way to prevent duplicates?

--
Brian Bushay (TeamB)
Bbushay@xxxxxxxxx


.



Relevant Pages

  • Re: Preventing Duplicates in BeforePost event.
    ... I got the BeforePost working but now the pending ... >updates will not post to the database. ... but the records are not in the database. ...
    (borland.public.delphi.database.ado)
  • RE: Master/Detail Transactions
    ... If any of the updates fails, ... pending parent and child rows within the scope of a transaction, ... cascade newly retrieved parent identity values down to pending child rows ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: how to move location of default database???? plz!
    ... fine, cool about the database, it probably amounts to how much tagging one ... updates - i woulda rolled them all back. ... No recent version of Windows does ... well when you have less than about 50MB to 100MB of free space. ...
    (microsoft.public.windowsmedia.player)
  • Re: Update Sql Server 2000 database from the HP3000
    ... collects those updates via ODBC every 10 or so seconds. ... essentially update the SQL database at the same time as the main ... Authorised and regulated by the Financial Services Authority. ...
    (comp.sys.hp.mpe)
  • Re: The right database for the job?
    ... Note that "many updates ... > the programmer that have to fix somebody elses code and/or database ... > devices under its control, it connects to a central "DB server" program ...
    (comp.databases)