Subject Re: Primary Key is allways null
Author mcrosman1957
Thank you Martijn

The solution is so simple!

As you have suggested, I have changed the 'Required' property of
NumReg filed of ClientDataset to False and the problem has been
solved.

Thank you very much.

Marcelo.


--- In ib-support@y..., "Martijn Tonies" <m.tonies@u...> wrote:
> Marcelo,
>
>
> If you use a trigger, you're assigning the value AT THE SERVER.
>
> Either set the Required property of your primary key field to False
> or fetch the value from the generator yourself:
>
> select gen_id(mygen, 1) as newvalue from rdb$database
>
> And use that value in your INSERT statement.
>
>
> With regards,
>
> Martijn Tonies
> InterBase Workbench - the developer tool for InterBase
> http://www.upscene.com
>
> Firebird Workbench - the developer tool for Firebird
> http://www.upscene.com
>
> Upscene Productions
> http://www.upscene.com
>
> "This is an object-oriented system.
> If we change anything, the users object."
>
> >
> > I am using Delphi 6 + Interbase 6.5
> >
> > My application uses:
> > ClientDataset + DataSource +
> > DataSetProvider +
> > IBQuery +
> > IBTransaction +
> > IBDatabase.
> >
> > I have created:
> > 1)A generator to increment the NumReg primary key of my table
PCOrc:
> > CREATE GENERATOR PCOrc_GEN;
> >
> > 2) A Trigger Set_NumReg_PCOrc:
> > SET TERM #
> > CREATE TRIGGER SET_NumReg_PCOrc FOR PLANCONORC
> > Active Before INSERT Position 0 AS
> > begin
> > IF (new.NumReg IS NULL) THEN
> > new.NumReg = gen_id(PCOrc_GEN,1);
> > end #
> > SET TERM ;#
> >
> > 3) I insert a new record executing:
> > ClientDataset.Insert
> >
> > After I have filled all the fields on the new insertion I execute
> > ClientDataset.Post.
> >
> > Then on the AfterPost event of ClientDataset I execute:
> > if (ClientDataset.ChangeCount > 0) then
> > ClientDataset.ApplyUpdates(-1);
> >
> > After the execution of ClientDatset.Post an EDBClient exception
is
> > raised informing that the "Field NumReg requires a value"
> >
> > The value of NumReg field is allways null.
> >
> > How can I solve this problem?
> >