How to get value of auto generated primary key after insert
Posted: Fri 18 Feb 2011 20:01
I am trying to insert an new user into my user table. The userID column is a primary key generated from Oracle sequence. I set Auto Generated Value = true but I noticed that the userID always ends up as 0. Of course inserting a user via a sql insert does properly generate a new sequence value.
Later I also tried combinations of Auto-Sync, Read-Only, and even set IdGenerator to the name of the oracle sequence name. I didn't expect changing these properties from their defaults would work either but I couldn't find an online example so I wanted to try it out to make sure. I'm also using the latest dotConnect for Oracle 6.1
I'm sure I'm overlooking something obvious. Any ideas (of even better a link to the documentation covering this so I can teach myself).
On a related note, I need the userID value returned so I can use it in my many to many UserRoles table. Do I have to call SubmitChanges() to insert the user, get the userID, and then create the UserRoles record and call SubmitChanges() a 2nd time?
Later I also tried combinations of Auto-Sync, Read-Only, and even set IdGenerator to the name of the oracle sequence name. I didn't expect changing these properties from their defaults would work either but I couldn't find an online example so I wanted to try it out to make sure. I'm also using the latest dotConnect for Oracle 6.1
I'm sure I'm overlooking something obvious. Any ideas (of even better a link to the documentation covering this so I can teach myself).
On a related note, I need the userID value returned so I can use it in my many to many UserRoles table. Do I have to call SubmitChanges() to insert the user, get the userID, and then create the UserRoles record and call SubmitChanges() a 2nd time?