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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:33:13+00:00 2026-05-26T23:33:13+00:00

I working in .Net Application. Here in my aspx page, i am having 3

  • 0

I working in .Net Application. Here in my aspx page, i am having 3 Tabs (i.e) Tab 1, Tab 2,Tab 3. The first Tab contains some Textbox controls, the Second tab contains some combo box controls and same as Third tab contains some controls. I want to save all these three tab controls to THREE different tables in SQL Database. Only one Stored Procedure should be used for this. The PRIMARY KEY of the FIRST table should be saved in the SECOND and THIRD table. ( LIKE, REFERENTIAL INSERT ). Here is my SP…

ALTER PROCEDURE [dbo].[Insert]
(@Name NVARCHAR(50))        
 AS
BEGIN
SET NOCOUNT ON
DECLARE @TableOnePrimaryKey INT

BEGIN

INSERT INTO TABLEONE(Name)
VALUES (@Name)               

SELECT @TableOnePrimaryKey=@@IDENTITY
SELECT CAST(@@IDENTITY AS INT)

INSERT INTO TABLETWO(TableTwoIDColumn)
VALUES (@TableOnePrimaryKey) 

SELECT @TableOnePrimaryKey=@@IDENTITY
SELECT CAST(@@IDENTITY AS INT)

INSERT INTO TABLETHREE(TableThreeIDColumn)
VALUES (@TableOnePrimaryKey)               

SELECT @TableOnePrimaryKey=@@IDENTITY
SELECT CAST(@@IDENTITY AS INT)

INSERT INTO TABLEFOUR(TableFourIDColumn)
VALUES (@TableOnePrimaryKey)  

END

But, its the TABLE ONE Primary key is not got saved in other tables. How to Fix this..

  • 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-26T23:33:13+00:00Added an answer on May 26, 2026 at 11:33 pm

    Use scope_identity() instead of @@identity. And you should not assign the value to @TableOnePrimaryKey more than once. If you have an identity column in the other tables you loose the identity you got from the first insert.

    ALTER PROCEDURE [dbo].[Insert]
    (@Name NVARCHAR(50))        
     AS
    BEGIN
      SET NOCOUNT ON
      DECLARE @TableOnePrimaryKey INT
    
      INSERT INTO TABLEONE(Name)
      VALUES (@Name)               
    
      SET @TableOnePrimaryKey=SCOPE_IDENTITY()
    
      INSERT INTO TABLETWO(TableTwoIDColumn)
      VALUES (@TableOnePrimaryKey) 
    
      INSERT INTO TABLETHREE(TableThreeIDColumn)
      VALUES (@TableOnePrimaryKey)               
    
      INSERT INTO TABLEFOUR(TableFourIDColumn)
      VALUES (@TableOnePrimaryKey)  
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working inside the context of an ASP.NET application I am creating a page that
i am working on a asp.net(with c#) web application and here i have problem.
Hello everyone :I am working on a .net mvc3 application. Here is my controller
I'm working in a .net application where we need to generate XML files on
I am working on a .NET application that displays multiple charts. My users would
I'm working on a .Net application which uses Asp.net 3.5 and Lucene.Net I am
I am working on a .NET application to reduce image file sizes using ImageMagick
I've been working on a .NET application and experiencing a memory error (I'm a
When working with an ASP.NET application in Visual Studio 2008, my errors window often
When working with an ASP.Net application, when I rebuild the solution, I would like

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.