Subject | how to use TIBOTable? |
---|---|
Author | jacobhavkrog |
Post date | 2011-05-14T19:14:49Z |
Hi - I am converting from a BDE paradox world, where you can use a TTable to insert a new row into a table, and easily retrieve the autogenerated primary key.
If there is a table "mytable" with a autoinc primary key field called "mytableID", it would be easy to insert a new row into the table, and afterwards know the mytableID of the row. Just like this:
with TTable.Create(nil) do
try
DatabaseName := 'mydb';
Tablename := 'mytable';
Open;
Insert;
FieldsByName('myfield').AsString := 'this is a new record';
Post;
ID := FieldsByName('mytableID').AsInteger;
finally
Free
end;
If I try to do the same thing with TIBOTable towards a firebird DB, the returned value ID is zero.
How do I do this? How do I know what ID the trigger gave the new record.
Thanks!
Jacob
If there is a table "mytable" with a autoinc primary key field called "mytableID", it would be easy to insert a new row into the table, and afterwards know the mytableID of the row. Just like this:
with TTable.Create(nil) do
try
DatabaseName := 'mydb';
Tablename := 'mytable';
Open;
Insert;
FieldsByName('myfield').AsString := 'this is a new record';
Post;
ID := FieldsByName('mytableID').AsInteger;
finally
Free
end;
If I try to do the same thing with TIBOTable towards a firebird DB, the returned value ID is zero.
How do I do this? How do I know what ID the trigger gave the new record.
Thanks!
Jacob