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

  • Home
  • SEARCH
  • 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 7540673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:41:53+00:00 2026-05-30T07:41:53+00:00

I have a SQL Server as backend for an asp.net application. Multiple people might

  • 0

I have a SQL Server as backend for an asp.net application. Multiple people might insert data in the same table ‘the same time…’.

When I read the solution/answer from this post: scope_identity vs ident_current

THEN I should not use the Ident_current because I could get the id of the insert of another user.

But using Select Scope_Identity(); returns me NULL while the Select IDENT_CURRENT('tableName') returns me the correct id which I checked with SQL Server Management Studio.

The insert statement I do within a SqlTransaction. The Select IDENT_CURRENT('tableName') is done after the transaction.

What do I wrong?

UPDATE:

My insert statement which is dynamically build together by a base class:

INSERT INTO TEST (NAME) VALUES (@Name)

The command’s Parameter collection has the value “xxx” and everything is fine inserted into the table.

I do NOT use stored procedures just pure SqlDataReader with C#.

commandText = "INSERT INTO TEST (NAME) VALUES ('Test1');Select Scopy_Identity();"

How can I get the last auto inc id running the above statement and should I call ExecuteNonQuery or ExecuteReader for the above because it has a INSERT and SELECT that’s confusing…

  • 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-05-30T07:41:54+00:00Added an answer on May 30, 2026 at 7:41 am

    just use the OUTPUT Clause (Transact-SQL) and you can insert the data and select back all (even multiple) identities in the same statement:

    INSERT INTO TEST (NAME) OUTPUT INSERTED.YourIdentity VALUES (@Name)
    

    working example:

    DECLARE @YourTable table (YourIdentity int identity(1,1) primary key, YourCol1 varchar(5))
    
    INSERT INTO @YourTable (YourCol1) OUTPUT INSERTED.YourIdentity VALUES ('ABC')
    

    OUTPUT:

    YourIdentity
    ------------
    1
    
    (1 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an asp.net mvc website with a SQL server backend. For every table
I have an ASP.NET MVC 3 application with a SQL Server 2005 database backend.
I have a ASP.NET application that connects to a SQL server backend on another
I have a asp.net-mvc website with a SQL server backend (using nhibernate for OR
I have an asp.net web application backed by SQL Server 2005, and I want
I have an ASP.NET MVC application that utilizes NHiberante and SQL Server 2008 on
I am building a very simple asp.net application that will have a SQL Server
I have an IIS 6.0-based C#/ASP.NET web site with a SQL server backend. I
I have an application I’m writing in access with a SQL server backend. One
I have a three tier system, SQL Server backend, hand written data access layer,

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.