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. C#
  4. Getting the last record autonumber value

Getting the last record autonumber value

Scheduled Pinned Locked Moved C#
csharpquestiondatabasesaleshelp
4 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.
  • T Offline
    T Offline
    TheCardinal
    wrote on last edited by
    #1

    Im using access database to store some customer information.

    I have a table with an autonumber field.

    I want to get the value of the autonumbered field, for the last added record in that table? So i can use it as my Customer ID for the next entry of customer details.

    if the last generated autonumber is
    Ex:
    100 ->

    the next customer id should be 101, can anyone please help or can point me to the right direction :)

    how do i do it using ado.net? Just learning c# and ado.net :)

    +============================================================================ Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

    G 1 Reply Last reply
    0
    • T TheCardinal

      Im using access database to store some customer information.

      I have a table with an autonumber field.

      I want to get the value of the autonumbered field, for the last added record in that table? So i can use it as my Customer ID for the next entry of customer details.

      if the last generated autonumber is
      Ex:
      100 ->

      the next customer id should be 101, can anyone please help or can point me to the right direction :)

      how do i do it using ado.net? Just learning c# and ado.net :)

      +============================================================================ Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Don't use the pre tag on the message. The font isn't that easy to read, and the text doesn't wrap. After you insert a record, use the query "select @@identity" to get the id that was created for the record.

      --- b { font-weight: normal; }

      T L 2 Replies Last reply
      0
      • G Guffa

        Don't use the pre tag on the message. The font isn't that easy to read, and the text doesn't wrap. After you insert a record, use the query "select @@identity" to get the id that was created for the record.

        --- b { font-weight: normal; }

        T Offline
        T Offline
        TheCardinal
        wrote on last edited by
        #3

        thanks Guffa for the reply ill check it out :) Sorry for the pre tag :)

        1 Reply Last reply
        0
        • G Guffa

          Don't use the pre tag on the message. The font isn't that easy to read, and the text doesn't wrap. After you insert a record, use the query "select @@identity" to get the id that was created for the record.

          --- b { font-weight: normal; }

          L Offline
          L Offline
          lainoo
          wrote on last edited by
          #4

          yes, Rows = table.Select("select @@identity"); in Sql Server INSERT INTO jobs (job_desc,min_lvl,max_lvl) VALUES ('Accountant',12,125) SELECT @@IDENTITY AS 'Identity' @@IDENTITY is SQL system variable datatable have very SQL method , So you think dataset like a small SQl server

          Agree ...

          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