Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    3

    Exclamation Unanswered: 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!

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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.

  3. #3
    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.

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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

  5. #5
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •