Page 1 of 1

KeyGen

Posted: Wed 12 Mar 2008 06:02
by rcmz
I need some samples on using KeyGen with TIBCQuery built in runtime

Where can I get this Info.

TIA
rcmz

Posted: Fri 14 Mar 2008 15:33
by Plash
Please see the following example:

Code: Select all

  IBCQuery1.SQL.Text := 'select * from emp';
  IBCQuery1.KeyFields := 'empno';
  IBCQuery1.KeyGenerator := 'emp_id';
  IBCQuery1.Open;
 
  IBCQuery1.Insert;
  IBCQuery1.FieldByName('ENAME').AsString := 'AAA';
  IBCQuery1.Post;

Posted: Fri 14 Mar 2008 15:53
by rcmz
Thanx for your response

But if I use

ibcquery.sql.text := 'INSERT CLIENTS (NAME)'+
'VALUES ('AAA')';
ibcquery.execute;

the id gets a null value but the record gets inserted.

the problem is with the id

TIA
Ramiro[/code]

Posted: Fri 14 Mar 2008 16:18
by Plash
KeyGenerator property can be used only when you open a SELECT statement, and insert records to this dataset.

If you execute INSERT statement, you should use the generator in this statement:

Code: Select all

INSERT INTO CLIENTS (ID, NAME)
VALUES (NEXT VALUE FOR my_gen, 'AAA')