Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row?

In VB .NET how do we get the new row ID number in an access database table BEFORE inserting the new row?

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdatabasetutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aeskan
    wrote on last edited by
    #1

    I'm programming with VB .NET 2010 and using a Microsoft Access Database file which is bound to my project as a Dataset. Now I want to know: BEFORE inserting a new row into my dataset table what will be the new ID number, or totally is it possible to know? Surely you know the autonumber ID of a table is different with row count number, for there may be deleted rows between the table rows. Like the following example: Row 0: ID=1 Row 1: ID=2 Row 2: ID=4 (ID number 3 is deleted) Row 3: ID=5 Row 4: ID=9 (ID numbers 6,7,8 are deleted) Now how do we know what ID number of Row 5 will be before inserting the new row? Perhaps ID numbers 10 and 11 are either deleted or not, so it may be 10, may be 11 or 12 or whatever! Is there a way to know it BEFORE adding or inserting the new row into the table? Thank you beforehand.

    P J 2 Replies Last reply
    0
    • A aeskan

      I'm programming with VB .NET 2010 and using a Microsoft Access Database file which is bound to my project as a Dataset. Now I want to know: BEFORE inserting a new row into my dataset table what will be the new ID number, or totally is it possible to know? Surely you know the autonumber ID of a table is different with row count number, for there may be deleted rows between the table rows. Like the following example: Row 0: ID=1 Row 1: ID=2 Row 2: ID=4 (ID number 3 is deleted) Row 3: ID=5 Row 4: ID=9 (ID numbers 6,7,8 are deleted) Now how do we know what ID number of Row 5 will be before inserting the new row? Perhaps ID numbers 10 and 11 are either deleted or not, so it may be 10, may be 11 or 12 or whatever! Is there a way to know it BEFORE adding or inserting the new row into the table? Thank you beforehand.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      There is no way to know beforehand if you are using a standard identity value. If you need to know this beforehand, you are either going to have to generate the value yourself, or use something like a GUID instead - which you can assign in your code.

      Forgive your enemies - it messes with their heads

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        There is no way to know beforehand if you are using a standard identity value. If you need to know this beforehand, you are either going to have to generate the value yourself, or use something like a GUID instead - which you can assign in your code.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

        A Offline
        A Offline
        aeskan
        wrote on last edited by
        #3

        Thank you Pete.

        1 Reply Last reply
        0
        • A aeskan

          I'm programming with VB .NET 2010 and using a Microsoft Access Database file which is bound to my project as a Dataset. Now I want to know: BEFORE inserting a new row into my dataset table what will be the new ID number, or totally is it possible to know? Surely you know the autonumber ID of a table is different with row count number, for there may be deleted rows between the table rows. Like the following example: Row 0: ID=1 Row 1: ID=2 Row 2: ID=4 (ID number 3 is deleted) Row 3: ID=5 Row 4: ID=9 (ID numbers 6,7,8 are deleted) Now how do we know what ID number of Row 5 will be before inserting the new row? Perhaps ID numbers 10 and 11 are either deleted or not, so it may be 10, may be 11 or 12 or whatever! Is there a way to know it BEFORE adding or inserting the new row into the table? Thank you beforehand.

          J Offline
          J Offline
          Jitheshvijayan
          wrote on last edited by
          #4

          One way is to store the last ID number in another table and increment it whenever a row is inserted into the table.

          A 1 Reply Last reply
          0
          • J Jitheshvijayan

            One way is to store the last ID number in another table and increment it whenever a row is inserted into the table.

            A Offline
            A Offline
            aeskan
            wrote on last edited by
            #5

            Yes that's the best way, thanks for your remark.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups