Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:11:52+00:00 2026-06-14T06:11:52+00:00

Is there a way in ADO.NET to retrieve the auto-generated ID after executing an

  • 0

Is there a way in ADO.NET to retrieve the auto-generated ID after executing an INSERT-statement? I know about SELECT @@IDENTITY for Sql Server and SELECT last_insert_id() for MySQL, but what I need is a database-independent way to retrieve the ID.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:11:53+00:00Added an answer on June 14, 2026 at 6:11 am

    I dont think a way exists, because the command to get last inserted id is vendor specific. What you can do is to incorporate the query to get last inserted id in your main query (which I understand is not what you want) and then write a C# function to read it irrespective of your db (without relying on specific ADO.NET type but on the methods specified on interface IDbDataReader or IDbCommand)

    Or else you will have to rely on some ORM solution like Entity Framework which will handle all this for you saving you from the hassle of manually getting last inserted id, though the implementation will be very db specific. You can see a nice discussion on that here:

    getting identity row value using ADO.NET Entity

    You can see this link which will give you some insight on directly accessing the records relying on dataadapters (but I dont like it).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to insert a row using ADO.Net without filling the dataset
I have created a set of tables by executing SQL script generated by ADO.NET
Using ADO.NET , what is the fastest way to retrieve data from the database
Is there an way using ADO.NET to determine if a table exists in a
Using .net 2 and ADO.NET. Is there a way to determine if a transaction
I am about to build a data access layer the good old ado.net way.
Is there a way to intercept/log all database calls from a .Net Assembly. The
I've got a ADO.NET question, Indeed, I'd like to know if it's possible to
I'm using ADO.NET to communicate some db, and searching for a way to avoid
I'm creating a project that is utilizing Quartz.NET (with ADO.NET DB storage). There is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.