I have to write a record to the database the I need a 100% surefire to grab the primary key and continue to my next page. where I will update that database based on my primary key and some extra gathered info.
the only time people ask for a method to retrieve the primary key is when said primary key happens to be a surrogate (such as an autonumber)
what they often overlook is that the table should also have a "real" primary key
that's the terminology that i prefer, although data modelling purists will rightly call it an alternate or candidate key
have you noticed how often you see threads on discussion forums that begin with "oh please help me, i have duplicates in my table, i want to remove all but the latest of the duplicates"
this is a direct result of not declaring a unique constraint to the "real" (or candidate) key
so...
your table should have a "real" key
hint: it will/should have a unique constraint
when you insert a row, you are supplying the values of the real key
so simply query the row back using those same values, and voila, there's your autonumber
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.