If I want to insert one row by the DBNavigaor "+" sign and a DBGrid, - I see an error message, because something like "invalid primary key".
What can I do, that my DBGrid / DBNavigator just writes new rows into my database and let the generator within firebird do his job to generate a new ID?
If you want the ID to be generated automatically, then don't put that field in the TDBGrid.
When the ID isn't used, it will be automatically generated.
But depending on your generator you could also let the new value generate on NULL or 0.
For NULL you would need to set the required property of the field to false.
That all depends on how your trigger looks.
Mine is this for LAND. So it will create a new ID for NULL but also for 0.
Anything else will just be accepted.
CREATE TRIGGER TR_LAND FOR LAND ACTIVE BEFORE INSERT POSITION 0 AS
BEGIN
IF ((NEW.LINKNUMMER IS NULL) OR (NEW.LINKNUMMER = 0)) THEN
NEW.LINKNUMMER = GEN_ID(GEN_LAND, 1);
END^
For NULL I also need to do this if I have the primary key in the SELECT and INSERT:
IBQuery1.FieldByName('LINKNUMMER').Required := false
otherwise you get an error that the field is NULL and needs to have a value because it's a primary key.
If I want to insert one row by the DBNavigaor "+" sign and a DBGrid, - I see an error message, because something like "invalid primary key".
BTW. PLEASE don't mention errors like "something like".
ALWAYS state the EXACT error message !!!!