CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2002
    Location
    West Virginia
    Posts
    131

    Auto numbering in ADO

    Hi,
    I am new to database programing and have this problem I can't find an answer to. This is the code I am using.
    [CODE]
    Set conData = New ADODB.Connection
    conData.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & App.Path & "\data.mdb"

    strSQL = "CREATE TABLE League (" & _
    "ID Integer NOT NULL IDENTITY(1,1) PRIMARY KEY," & _
    "LeagueName Varchar(50)," & _
    "BowlingCenter Varchar(50));"
    conData.Execute strSQL
    Set conData = Nothing
    [CODE]
    However when I add data the ID (primary key) does not increment. All my ID's are 1.
    What am I doing wrong?
    Thanks for your help.
    Wayne

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Auto numbering in ADO

    IDENTITY is called COUNTER in access:
    use something like :
    Code:
    Create table ABC(MyID COUNTER primary key )
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Jun 2002
    Location
    West Virginia
    Posts
    131

    Re: Auto numbering in ADO

    I already tried that but didn't work. I get a sql syntax error. I found out that if I made the primary key a long then it worked. Don't know why but it does.
    Thanks for your reply,
    Wayne
    Last edited by WayneS; October 28th, 2004 at 07:08 AM.

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Auto numbering in ADO

    Hi
    this works great in Access XP:
    Code:
    CREATE TABLE League (ID counter PRIMARY KEY,
    LeagueName Text,
    BowlingCenter Text)
    What version of access do you use ?
    Do you get any Error messages ?
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  5. #5
    Join Date
    Jun 2002
    Location
    West Virginia
    Posts
    131

    Re: Auto numbering in ADO

    The problem is I don't have Access. Wish I did. Had to do it all with ADO and SQL.
    Thanks anyway,
    Wayne

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured