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. Database & SysAdmin
  3. Database
  4. Getting id of last inserted row

Getting id of last inserted row

Scheduled Pinned Locked Moved Database
csharpdatabasehardwarequestion
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.
  • E Offline
    E Offline
    error1408
    wrote on last edited by
    #1

    Hi, i have two tables with a 1:n relation. I insert a new row in the first table without knowing the id of it, because of a trigger in the table. Now i want to insert a bunch of rows in the second table, but i need the id of the before inserted row because of the foreign key. How could i do that?:confused: I use a firebird embedded db with .net + C#

    K M 2 Replies Last reply
    0
    • E error1408

      Hi, i have two tables with a 1:n relation. I insert a new row in the first table without knowing the id of it, because of a trigger in the table. Now i want to insert a bunch of rows in the second table, but i need the id of the before inserted row because of the foreign key. How could i do that?:confused: I use a firebird embedded db with .net + C#

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      In MS SQL Server you can call the function SCOPE_IDENTITY() and it will return the identity of the row you just inserted. Hope that helps. Ben

      1 Reply Last reply
      0
      • E error1408

        Hi, i have two tables with a 1:n relation. I insert a new row in the first table without knowing the id of it, because of a trigger in the table. Now i want to insert a bunch of rows in the second table, but i need the id of the before inserted row because of the foreign key. How could i do that?:confused: I use a firebird embedded db with .net + C#

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        Just set a parameter equal to @@IDENTITY.


        CleaKO

        "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
        "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

        E 1 Reply Last reply
        0
        • M Marcus J Smith

          Just set a parameter equal to @@IDENTITY.


          CleaKO

          "I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy
          "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)

          E Offline
          E Offline
          error1408
          wrote on last edited by
          #4

          I found a solution select gen_id(, 0) from rdb\$database @cleako Could you post an small example? I'm new to programming with databases. Thank you

          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