CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2001
    Location
    israel
    Posts
    99

    AutoNumber in access

    hi guys,

    for my project i created a database in Access 2000.
    In one of my tables my primary key is an autonumber.

    my table fields are:

    StatusNumber -> Autonumber
    StatusName -> Text

    in my project i wrote a statement that insert a new StatusName but i get an error becouze it needs me to send also a new StatusNumber.

    why does the AutoNumber field need me to give him a number? how can i avoid that?

    thanks,
    ohad.



  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: AutoNumber in access

    When iserting data using a SQL statement, you can specify which column the data need to go in. I assume the table is called tblStatus

    ' This will insert the first value in the first field, the second in the second field
    INSERT INTO tblStatus VALUES(5,"Sometext")

    ' This will insert "SomeText" into StatusName, and 5 into StatusNumber
    INSERT INTO tblStatus (StatusName, StatusNumber) VALUES("SomeText",5)

    ' both statements will fail, because statusnumber is autonumber, therefore, we omit it
    INSERT INTO tblStatus (StatusName) VALUES("SomeText")




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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