Inserting data from two tables into one c#

Fypracing.com

New Member
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 \[code\]Task\[/code\] and has \[code\]task_id\[/code\] as a primary key, \[code\]task_name\[/code\] and \[code\]task_description\[/code\]. The second one is - \[code\]Resource\[/code\] and has \[code\]resource_id\[/code\] as a primary key and \[code\]resource_name\[/code\]. 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 \[code\]task_id\[/code\] and \[code\]resource_id\[/code\] into a third table called \[code\]Task_resource\[/code\]. It has a primary key \[code\]task_resource_id\[/code\](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 \[code\]SELECT data from the other 2 tables WHERE task_id=1\[/code\]).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 \[code\]task_id\[/code\] into the \[code\]Resource\[/code\] table which references the \[code\]task_id\[/code\] in \[code\]Task\[/code\].But then again, how to insert that id, since I don't know it ?
 
Back
Top