Updates not applied when using cloned datasets
- From: "Chris Cooper" <cooperc@xxxxxxxxxxx>
- Date: Mon, 13 Jun 2005 16:41:59 -0600
If I use a cloned dataset my updates on the original datasets do not get
sent to the database. I have three TADODatasets, DsetHeadings is a master
to dsetReasons (i.e. dsetReasons.Datasource = dsetHeadings). If I make
changes to all three datasets and then execute the following save routine,
UpdateBatch will not work (no changes sent to the database) on dsetHeadings
or dsetReasons if the CheckSequenceValues routine is called. The
CheckSequenceValues function works just fine. I don't get any exceptions or
errors. When running a trace on the database (MSSQL) then update commands
never show up, it's as if the weren't any changes made to the dsetHeadings
or dsetReasons dataset. I've noted below that if I don't call the
CheckSequenceValues function the UpdateBatch command works (updates are
applied) and I do see the update while running the trace on the database.
function TfrmSettings.SaveData: Boolean;
var i : integer;
// ***** Note: If I don't call this rutine the BatchUpdates will work
******* //
function CheckSequenceValues(ds : TADODataSet; SeqFldName : String):
Boolean;
var cloneset : TADODataSet;
RS : _Recordset;
begin
Result := True;
CloneSet := TADODataSet.Create(nil);
try
CloneSet.Connection := ds.Connection;
RS := ds.Recordset.Clone(adLockUnspecified);
RS.Set_ActiveConnection(nil);
CloneSet.Recordset := RS;
ds.First;
while not(ds.Eof) do
begin
CloneSet.Filtered := False;
CloneSet.Filter := SeqFldName + ' = ' +
ds.FieldByName(SeqFldName).AsString;
if SeqFldName = 'DISPLAY_SEQ' then
CloneSet.Filter := CloneSet.Filter + ' AND HEADING_ID = ' +
ds.FieldByName('HEADING_ID').AsString
else
CloneSet.Filter := CloneSet.Filter + ' AND DEPT_ID = ' +
ds.FieldByName('DEPT_ID').AsString;
CloneSet.Filtered := True;
if CloneSet.RecordCount > 1 then
begin
Result := False;
Break;
end;
ds.Next;
end;
finally
CloneSet.Filtered := False;
CloneSet.Close;
CloneSet.Free;
end;
end;
begin
Result := False;
with dsetHeadings do
begin
First;
while not(Eof) do
begin
if not(CheckSequenceValues(dsetReasons.DataSet, 'DISPLAY_SEQ')) then
begin
MessageDlg('You have an error', mtInformation, [mbOK], 0);
Exit;
end;
Next;
end;
end;
if not(CheckSequenceValues(dsetHeadings, 'SEQ_NUM')) then
begin
MessageDlg('You have an error', mtInformation, [mbOK], 0);
Exit;
end;
dmAdoConnections.conANSR.BeginTrans;
try
dsetReasons.UpdateBatch(arAll);
dsetHeadings.UpdateBatch(arAll);
dsetSetting.UpdateBatch(arAll); // *** Note: This update always works,
it's not used in the CheckSequenceValues rutine *** //
dmAdoConnections.conANSR.CommitTrans;
result := True;
except
dmAdoConnections.conANSR.RollbackTrans;
end;
end;
.
- Follow-Ups:
- Re: Updates not applied when using cloned datasets
- From: Viatcheslav V. Vassiliev
- Re: Updates not applied when using cloned datasets
- Prev by Date: Re: Please help Dynamic ADO Query
- Next by Date: Re: How to check if table exists
- Previous by thread: Import text file
- Next by thread: Re: Updates not applied when using cloned datasets
- Index(es):
Relevant Pages
|