Oracle Database how to get ID from newly added row.....

Posts   
 
    
josvdboom
User
Posts: 2
Joined: 15-Nov-2007
# Posted on: 15-Nov-2007 17:12:43   

Hello,

I use the following code... But the GenHeader.Id stays 0. If i look in the database the row is added and has its own id.

I added the AlwaysFetchOutput line but this did not help.

I use an Oracle express 10g database. I fill some variables for the GenHeaderEntity and then save it. This is all working correct.

                        if (headerSaved == false) {
                            GenHeader.IsNew = true;
                            GenHeader.Save(null, true);
                            GenHeader.Refetch();
                            headerSaved = true;
                        }
                        GenHeader.AlwaysFetchOutput = true;
                        outPut.GenericHeader = GenHeader.Id;
                        outPut.StatusId = 1;
                        outPut.Save();  --> Gives an error because the foreign key GenHeader.Id == 0.

Thanx...

Jos

CSharpner
User
Posts: 28
Joined: 03-Jun-2007
# Posted on: 15-Nov-2007 20:02:13   

Try the following:

  • In the designer, right-click your entity and choose "Edit / Properties".
  • Select your column that is an auto-generated value (I'm assuming you're using a Sequence to generate it on the database side?)
  • At the bottom, in the "Field Properties" tab, check "Is Identity / Sequence field".
  • The "Sequence Used" drop down list box will become enabled. Select the sequence.
  • Regenerate your code and recompile. Now, when you save a new entity instance, that field will have the new value in it on the client side.
josvdboom
User
Posts: 2
Joined: 15-Nov-2007
# Posted on: 16-Nov-2007 11:24:30   

Thanx for the good and quick response!!

Jos smile