Re: Updates not applied when using cloned datasets



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;
>
>


.



Relevant Pages

  • Updates not applied when using cloned datasets
    ... If I use a cloned dataset my updates on the original datasets do not get ... I have three TADODatasets, DsetHeadings is a master ... UpdateBatch will not work (no changes sent to the database) on dsetHeadings ...
    (borland.public.delphi.database.ado)
  • 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)
  • Re: A different definition of MINUS, Part 3
    ... can actually be the value of the database at any set point in time. ... updates, on the other hand, assert which possible value for the ... neither the algebra nor the calculus are sufficient when it comes to ... To extend the analogy to view updates, we also have an input delta ...
    (comp.databases.theory)