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. [Access database] how to get the last row inserted?

[Access database] how to get the last row inserted?

Scheduled Pinned Locked Moved C#
databasetutorialquestion
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
    Susuko
    wrote on last edited by
    #1

    i want to insert a new row inside my microsoft access database, i do it, but i need it immediately. how?

    N M 2 Replies Last reply
    0
    • S Susuko

      i want to insert a new row inside my microsoft access database, i do it, but i need it immediately. how?

      N Offline
      N Offline
      NaNg15241
      wrote on last edited by
      #2

      Although this is a question to database forum (if there is), I know a little about it so I'll help... I personally work with database that doesn't stop to work (there are always a few people that can use the database), you should always take that risk! because if some-one inserts a row while you insert a row, you can both edit the same row in the end. I'll show you the command line for the last inserted row, and then I'm going to show you the better way. So this is command to get the last row: Select Top 1 * From tblTable Order By DESC (ofcourse no case-sensetive in here) tblTable = the table ID-Field = the ID or some other field that increases by time (eg. Date\Time) Now this is not good because if two people add a row, at the same time, they will, in the end see the same row, the last row inserted, and not their own. The better way which I prefer is to save the variables from the insert command, and just do a "Where" statement in the select command. eg: Select * from tblTable Where = '{0}' And = '{1}' etc. etc... Hope I helped... NaNg

      1 Reply Last reply
      0
      • S Susuko

        i want to insert a new row inside my microsoft access database, i do it, but i need it immediately. how?

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        Hi! Don't know if I understand what you want, but if you need the value of an AutoValue that Access has assigned to a field in your newly-inserted row, you can look for "@@Identity". Another way could be to create your IDs on your own - use a GUID and you can be sure that it's unique and you have its value before you even insert the row into the database. Regards, mav -- Black holes are the places where god divided by 0...

        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