Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How to update data in a TClientDataset? by towerbase
Posted: 14 Jan 04

You can traverse a TClientDataset using First, Next, Last, Prior, FindKey, FindNearest and other functions/procedures.  When you want to update data in a record you can explicitly put the record into Edit mode, change the data and Post it as in this example where the TClientDataset has been instantiated with the name of cds.

  cds.FieldByName('credit').AsInteger := 500;

At this point the data has been added to a change log in the TClientDataset but it has not been updated in the physical database.  The change log enables updates to be undone quite easily.

Alternatively, you can update the data using standard visual Data Access controls such as TDBEdit, TDBGrid and so
on.  Again, the data is only changed within TClientDataset and not in the real database.

You must call ApplyUpdates to actually send the updates to the real database:


ApplyUpdates is actually a function that returns the number of updates that failed.  Failure could be caused by someone else updating the record.  The parameter passed to ApplyUpdates specifies the number of updates that you will permit to fail.  If this number is exceeded all the updates are backed out.  If the number of updates is specified as -1 then it indicates that you will tolerate any number of failures.  A better way of coding the ApplyUpdate might be:

  if cds.ApplyUpdates(0) > 0 then
    ShowMessage ('Update failed');


Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close