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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:06:31+00:00 2026-06-15T11:06:31+00:00

I have 3 tables. I create a task and upload a resource at the

  • 0

I have 3 tables. I create a task and upload a resource at the same time. The data is saved in two tables – one for task information and one for the resource.

I am trying to insert the primary keys of the two tables into a third table. The first table is called Task and has task_id as a primary key, task_name and task_description. The second one is – Resource and has resource_id as a primary key and resource_name. Both id’s have the auto increment option, so when I enter data to the table, I don’t fill the ids.

I want to insert task_id and resource_id into a third table called Task_resource. It has a primary key task_resource_id(again with auto increment option).

The question is how to do it, since I don’t know the id’s?

The reason for this is that one task can have many resources and in the third table I can combine them, and therefore search of them(for example something like SELECT data from the other 2 tables WHERE task_id=1).

I am having a asp.net Web Application and a mssql database. I use c#.

I know that a possible solution could be inserting a column called task_id into the Resource table which references the task_id in Task.

But then again, how to insert that id, since I don’t know it ?

  • 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-15T11:06:33+00:00Added an answer on June 15, 2026 at 11:06 am

    Do the insert on the first table and then return the scope_identity() from the query. Then when you insert into the second table you have the ID? Or if you are using LINQ

    //create the object
    Task task = new Task{
    
    task_name = src.taskName,
    task_description = src.taskDescription
    
    }
    
    context.Tasks.InsertOnSubmit(task);
    context.SubmitChanges();
    
    //do second insert
    Int32 taskIDFromLastInsert = task.task_id;
    
    Resource res = new Resource{
    
    resource_name = scr.ResourceName,
    task_id = taskIDFromLastInsert // optional if you want to change your structure
    
    }
    

    context.Resources.InsertOnSubmit(res);
    context.SubmitChanges();

    Int32 resourceIDFromLastInsert = resource_id;

    You now have both ID’s if you really want to insert into third table

    It is a clean way to reference your data

    After the inserts run your query against the data.

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

Sidebar

Related Questions

I have two tables to be printed in same page. Data for those tables
I have two tables. First one: create table history ( id integer primary key,
I have two tables one to store a task and one to evaluate the
I have two tables: CREATE TABLE [dbo].[Task]( [SysTask] [int] IDENTITY(1,1) NOT NULL, [TaskStatus] [int]
In my dbsql file, I have two CREATE TABLES the first works and the
I have two tables : create table CurrentDay ( ID int identity primary key,
I have two tables one named Person , which contains columns ID and Name
I have a task: work with many blogs in one time, from one shell.
i have 2 tables CREATE TABLE if not exists tag_name( + tagid INTEGER PRIMARY
I have 2 tables: CREATE TABLE `product_det` ( `id` bigint(12) unsigned NOT NULL AUTO_INCREMENT,

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.