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 a latest value that was inserted into a database.

getting a latest value that was inserted into a database.

Scheduled Pinned Locked Moved C#
databasesql-servervisual-studiosysadminhelp
3 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.
  • S Offline
    S Offline
    steve_rm
    wrote on last edited by
    #1

    Hello, I have a table with the primary key being a auto incremented value (IDNumber). I need to retrieve the latest value that was inserted into the database. So if the latest IDNumber is 100, I have to somehow pull this number from the database, so I can use it in my program. The main problem is, if the program is first started I need to get this value. I am using VS 2005 and SQL server 2005. Is there a simple way to do this. Thanks in advance, Steve

    S N 2 Replies Last reply
    0
    • S steve_rm

      Hello, I have a table with the primary key being a auto incremented value (IDNumber). I need to retrieve the latest value that was inserted into the database. So if the latest IDNumber is 100, I have to somehow pull this number from the database, so I can use it in my program. The main problem is, if the program is first started I need to get this value. I am using VS 2005 and SQL server 2005. Is there a simple way to do this. Thanks in advance, Steve

      S Offline
      S Offline
      sam
      wrote on last edited by
      #2

      fire a query which would fetch max of ur primary key column. e.g. Select Column1,Column2 FROM Table WHERE PrimaryKey = SELECT MAX(PrimaryKey) FROM Table sameer

      1 Reply Last reply
      0
      • S steve_rm

        Hello, I have a table with the primary key being a auto incremented value (IDNumber). I need to retrieve the latest value that was inserted into the database. So if the latest IDNumber is 100, I have to somehow pull this number from the database, so I can use it in my program. The main problem is, if the program is first started I need to get this value. I am using VS 2005 and SQL server 2005. Is there a simple way to do this. Thanks in advance, Steve

        N Offline
        N Offline
        Navi15
        wrote on last edited by
        #3

        use IDENT_CURRENT( 'table_name' ) to get the last identity value generated for a specified table or view in any session and any scope.

        Naveen G MCSD.Net

        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