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 8791217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:48:46+00:00 2026-06-13T22:48:46+00:00

I have a table Student . This table has a column ID which is

  • 0

I have a table Student. This table has a column ID which is auto-increment. I want to write a stored procedure to add a new student and return the ID. I’m newbie at this.

This is my code. Please check if it’s wrong and fix for me and show me how to code to use it in C#. I used Entity Framework 4.

@Name NVARCHAR(50),
@Birthday DATETIME, 
@ID bigint OUTPUT 
AS 
BEGIN
    SET XACT_ABORT ON 

    BEGIN 
       INSERT INTO [Student](Name, Birthday) VALUES (@Name, @Birthday);  
       SELECT @ID = SCOPE_IDENTITY()
    END
END
  • 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-13T22:48:46+00:00Added an answer on June 13, 2026 at 10:48 pm

    It is better you can C# code instead SP when your working with EF4.

    Using Entity Framework, this is all done automagically for you.

    using (MyEntities context = new MyEntities())
    {
        var student =  new Student()
        {
          Name = "some value",
          Birthday = "some Birthday"
        };
    
        context.Students.AddObject(student);
    
        context.SaveChanges();
    
        int ID = student.ID; // You will get here the Auto-Incremented table ID value.
    }
    

    Saving in Entity Framework will automatically update the “auto-increment” ID column. You just read it out after the call to .SaveChanges();

    EDIT:

    Also read this post if you encounter any issues getting the “auto-increment” ID value.

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

Sidebar

Related Questions

I have a database table named 'student' in which there is one column named
I have a database table named tree1, which has a table names student_details.This table
I have a SQL table called StudentMarks.which consist of StudentID,SubjectName,SubjectMark I want to write
Currently, I have a table that has a column which has a datatype enum.
I have a database which has one table, Schools. This table also has latitude
I have two tables associated by FK. Table student is mapped like this: @Entity
i have a table which consists of student details like roll no, Name, age.
I have a table named 'Attendance' which is used to record student attendance time
I am new to SQL so hopefully this has an easy answer. I have
I have a table student like this id | name | zip 1 |

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.