Delphi Database, Delphi Components from ComponentAce
Products Download Order Contact us
Adding New Records
Previous  Top  Next



An active dataset must be in dsInsert mode before an application can add new records. In code, you can use the Insert or Append methods to put a dataset into dsInsert mode if the read-only CanModify property for the dataset is True.

Once a dataset is in dsInsert mode, a user or application can enter values into the fields associated with the new record. Except for the grid and navigational controls, there is no visible difference to a user between Insert and Append. On a call to Insert, an empty row appears in a grid above what was the current record. On a call to Append, the grid is scrolled to the last record in the dataset, an empty row appears at the bottom of the grid, and the Next and Last buttons are dimmed on any navigator component associated with the dataset.

Data-aware controls for which inserting is enabled automatically call Post when a user executes any action that changes which record is current (such as moving to a different record in a grid). Otherwise you must call Post in your code.
Post writes the new record to the database.

Example:

with ABSTable1 do
begin
  Insert;
  FieldByName('FirstName'
).AsString := 'John';
  FieldByName('LastName'
).AsString := 'Smith';
  FieldByName('Salary'
).AsFloat := 1999.95;
  Post;
end;

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Mar 28, 2024