Question : Firebird AutoID VB.net code

i use VB.net 2008 and firebird 2.1.3. how ti get the auto id work.

pls provide vb.net 2008 code.

thank you

Answer : Firebird AutoID VB.net code

You will have to execute a script against the database.  This is a once of excercise, otherwise, use a db management tool like ibexpert.  the script will be two parts:

--Here we create the generator, in FB 2.5 it is called a sequence
CREATE GENERATOR GEN_ADDRESS_ID;



--Here we create the trigger
CREATE OR ALTER TRIGGER ADDRESS_BI FOR ADDRESS
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
    NEW.ID = GEN_ID(GEN_ADDRESS_ID,1);
END

When you post data to the table, the trigger will fire and set the value of the ID column to the next value.  Remember that, when you use it like this you will not be able to see the ID of the new record, unless you do a (select max(ID) from <tablename> where user = CurrentUser. (to ensure you get the ID that was created by your transaction: user will be a column on your table, also populated by a trigger similar to the above)).  Read up on triggers, Stored procedures, views and generators on ibphoenix.

You will be surprised at the power of Firebird.
Random Solutions  
 
programming4us programming4us