If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 15: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, 19:18
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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, 16: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 16:56.
Reply With Quote
  #4 (permalink)  
Old 10-13-04, 19:50
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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, 05: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

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