Recent

Author Topic: How to add records in a DBF table  (Read 11092 times)

ecitoyen

  • Jr. Member
  • **
  • Posts: 51
How to add records in a DBF table
« on: July 14, 2010, 04:30:56 pm »
 :)
In a Lazarus example...

In the following example, we create a table with 2 field 
for each records

   Dbf1.FilePathFull := '/path/to/my/database';
   Dbf1.TableName := 'dvds';
   With Dbf1.FieldDefs do begin
       Add('Name', ftString, 80, True);
       Add('Description', ftMemo, 0, False);
       Add('Rating', ftString, 5, False);
   end;
   Dbf1.CreateTable;

 Id and Name
 But Now, how I can add records with employees Name.
 (I suppose that the field Id(with ftAutoInc) will
 be incremented by addind records)

 With dBase I used
 Append Blank
 Replace Name with Employename
 close databases

I Suppose Dbf1.Edit... but i don't know how to ?



Thanks a lot....

xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Re: How to add records in a DBF table
« Reply #1 on: July 14, 2010, 04:44:54 pm »
Example


Dbf_ConnectionName.Insert;
Dbf_ConnectionName.FieldByName('NameField').AsInteger:=1;
Dbf_ConnectionName.FieldByName('NameField').AsString:='Hello world';
Dbf_ConnectionName.Post;
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ecitoyen

  • Jr. Member
  • **
  • Posts: 51
Re: How to add records in a DBF table
« Reply #2 on: July 14, 2010, 07:10:31 pm »
 :D :D ;D
I do...

 Dbf9.Edit;
 Dbf9.FieldByName('fNOPTF').AsInteger:= NEWPLATE;
 Dbf9.Post;

to write on an existing record...

later i will try to add a new record with .insert as you told...

Tanks a lot... I'm appreciating your support...

xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Re: How to add records in a DBF table
« Reply #3 on: July 15, 2010, 07:43:55 am »
Dbf9.Insert;
Dbf9.FieldByName('fNOPTF').AsInteger:= NEWPLATE;
Dbf9.Post;

NEWPLATE is a integer variable!

 ;)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1