Re: Updates not applied when using cloned datasets
- From: "Chris Cooper" <cooperc@xxxxxxxxxxx>
- Date: Tue, 14 Jun 2005 11:41:28 -0600
I found the problem. I had to disconnect the detail datasource...
dsetReasons.datasource = nil
dsetReasons.MasterFields := ''
dsetReasons.IndexFieldNames := ''
Then execute the UpdateBatch and then reconnect the detail to the master.
"Viatcheslav V. Vassiliev" <support@xxxxxxxxxxxxxxx> wrote in message
news:42ae831d@xxxxxxxxxxxxxxxxxxxxxxxxx
When you clone recordset, you clone only cursor (i.e. current position,
filter, sort), not data. Remove this line
RS.Set_ActiveConnection(nil);
it dissasociates recordset from connection.
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Chris Cooper" <cooperc@xxxxxxxxxxx> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:42ae0bb6$1@xxxxxxxxxxxxxxxxxxxxxxxxx
> 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;
>
>
.
- References:
- Updates not applied when using cloned datasets
- From: Chris Cooper
- Re: Updates not applied when using cloned datasets
- From: Viatcheslav V. Vassiliev
- Updates not applied when using cloned datasets
- Prev by Date: Re: Please help Dynamic ADO Query
- Next by Date: Re: Please help Dynamic ADO Query
- Previous by thread: Re: Updates not applied when using cloned datasets
- Next by thread: Locate a record and show that record on a form
- Index(es):
Relevant Pages
|
|