Click here to Skip to main content
16,012,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am a newbie to C# and ASP.NET programming, i have created a database which has 6 tables connected to each other by foreign keys.

my problem is how do i insert data into all the tables at once considering the foreign keys they have.

i just need a sample script which shows how to insert data into all the six tables at once..

thank you for your in advance.

i need a sample with
sqlcommand AND dataset AND linq
you can Supposed northwind db for sample
Posted
Updated 4-May-13 10:41am
v2

1 solution

You can't. You can only INSERT into one table at a time. The trick is to do the insert for the top-level record first, retrieve the ID of that record, then use that to do the inserts for the other tables.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900