Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Creating an auto incrementing column with ASP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-11-04, 16:42
maniaccoder maniaccoder is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Exclamation Creating an auto incrementing column with ASP

Hello!

I wanna create an auto incrementing column with ASP. The code that i use to do this is below. This code don't works. But why?! I couldn't understand... Is there anyone who knows that how can I do this operation?

Code:
SQL = "ALTER TABLE [" & table_name & "] " SQL = SQL & " ADD COLUMN [" & field_name& "] " SQL = SQL & " adInteger " SQL = SQL & " IDENTITY " conn.execute SQL

P.S. This code works very good. It creates a column as integer and don't create any errors on ASP page but the created column isn't auto increment!
Reply With Quote
  #2 (permalink)  
Old 10-11-04, 20:18
rokslide rokslide is offline
Coffee Minion
 
Join Date: Nov 2003
Location: Sydney
Posts: 1,515
Shouldn't it be more like....
Code:
SQL = "ALTER TABLE [" & table_name & "] " SQL = SQL & " ADD COLUMN [" & field_name& "] " SQL = SQL & " adInteger " SQL = SQL & " NOT NULL IDENTITY (1, 1) " conn.execute SQL
but it would really depend on what database you were working with (I am assuming it is MS SQL.
Reply With Quote
  #3 (permalink)  
Old 10-13-04, 17:42
maniaccoder maniaccoder is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Ah, sorry! How could I forget to saying the database type which I work on! I use Microsoft Access, similarly with all most of ASP coders. Thanks you for your answer(s).

I tried your code and it gives an error on ALTER TABLE state. :'(

Last edited by maniaccoder : 10-13-04 at 17:56.
Reply With Quote
  #4 (permalink)  
Old 10-13-04, 20:50
rokslide rokslide is offline
Coffee Minion
 
Join Date: Nov 2003
Location: Sydney
Posts: 1,515
Okie, had a look around and I can't find any sql to help you, but this article may be of use....

http://imar.spaanjaars.com/QuickDocI...QUICKDOCID=143
Reply With Quote
  #5 (permalink)  
Old 10-14-04, 06:11
maniaccoder maniaccoder is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Code is working!

Thanks for your interest with my problem. The article that you referred to me is very usefull and it solved all my problem. Code is working very clearly! Ugghh!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On