Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Retrieving the Auto-increment number?

Quote Reply
Retrieving the Auto-increment number?
I have a table setup with an auto-increment field (the PK). I am not using the "auto generated" forms (eg. calling the DbSQL::HTML:: template routines)... I'm creating my own form elements within the templates.

Question: How do I use this auto incremented field? Do I just leave it blank and let the database fill it in or do I need to query the database for the new ID number and insert it into my form that the user fills out?

When I just leave the field blank, I get this error "Cannot insert duplicate key in object 'Claims'". I can delete the exising record but then soon after I just get the same error. As if it is not incrementing the ID field. There seems to be very little documentation on this specific feature.
Quote Reply
Re: [LanceWilson2] Retrieving the Auto-increment number? In reply to
Sorry about the late reply.

You just leave the filed blank in the add form. If you could send me your dbsql access info, I'll take a look.


Quote Reply
Re: [TheStone] Retrieving the Auto-increment number? In reply to
Actually, after a totally last effort attempt I was inspecting the SQL table in Access and noticed that the (Auto Increment) feature was not turned on for my table. I enable it (it is called Identity in Access-- who knows why) and all of a sudden it all worked. You were right you don't need to use that field at all it just auto increments it.

I'm guessing that when I setup the table that field was not created as an "ai" field and so the code to let the SQL server know that was never processed. I then later added the ai field into the def file rather than deleting the table and recreating it the correct way. Out of pure curiosity, is there any way to make a field auto-increment after the table is created? (other than manually turning it on in SQL)

Thank you for your willingness to help me on this problem but I think I got it all figured out now. Maybe you can help me on my next problem... see new posting in this forum. Wink