Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2004, 07:49 AM
Registered User
 
Join Date: Nov 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert new record ID

I have an Access database with the ID field being the primary key.

I want to INSERT a new record into the database but if I don't enter ID field, I get an error "Primary key can't be null value". I understand why I get it but is there any way for Access to automatically generate a new value for ID when I INSERT a new record?

Otherwise, it seems I have to go through the database each time I want to INSERT a record and check for the highest ID value. Is this correct?

Thanks.

Howard

 
Old January 14th, 2004, 08:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Access should automatically generate a new value for ID when a new record is inserted. My guess is there's something wrong with your insert statement (you shouldn't put the ID field in the field list). Show us your query!
 
Old January 14th, 2004, 09:33 AM
Registered User
 
Join Date: Jun 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried to set the Data type for the ID field to AutoNumber?

Regards

 
Old January 14th, 2004, 10:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

pgtips, will access automatically add a value if 'AutoNumber' has not been added? I was under the impression that you have to add autonumber for access to auto increment like Malu pointed out.

 
Old January 14th, 2004, 10:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by stu9820
 pgtips, will access automatically add a value if 'AutoNumber' has not been added? I was under the impression that you have to add autonumber for access to auto increment like Malu pointed out.
No it won't. I took it as read that the field was actually an autonumber field, but perhaps its not.
 
Old January 14th, 2004, 12:03 PM
Registered User
 
Join Date: Nov 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You were right, I didn't have it set as an autonumber.

Thanks.

HL







Similar Threads
Thread Thread Starter Forum Replies Last Post
get last record id using mySQL GregH Classic ASP Databases 6 May 11th, 2008 08:29 PM
Insert Record & retrieve ID gundulf ADO.NET 5 July 12th, 2007 10:03 PM
Last record inserted ID ADAC Programming VB Databases Basics 1 June 5th, 2006 02:41 PM
ASP Insert - Get Record ID llowe Classic ASP Databases 2 March 24th, 2004 11:11 AM
Record ID sinner Classic ASP Databases 12 February 28th, 2004 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.