Click here to Skip to main content
16,019,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've two tables linked by one to many relation,
first table is (Bill's) and the second is (Bill details)

From C# WinForms i want to insert one record into Bills table and multiple records into Details table
using a stored procedure and parameters sent from the WindowsForm as usual

What I have tried:

i tried to use a sqlcommand to insert single record into "bills table"
then use a "for" loop to execute another sqlcommand to insert multiple records in details table linked to the previous table(One to many) relation
But is there a better way to do that or that's the only way?
Posted
Updated 3-Jun-17 14:39pm

1 solution

That's just about the only way to do it. The Bill record has to go first, get its ID, then you include that in the Details records (foreign key). If you're going to have records that have a foreign key (related ID in a separate table), the foreign record has to exist first.
 
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