Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want insert record in multiple table but suppose i have two table one have primary key another have foreign key and insert record into this two table at one time.plz help me?
Posted

1 solution

The best way is to create a stored procedure, if you can - and use a transaction within that.
If not, then use a Transaction in your "normal" code.
But the procedure is the same in either case: write the Primary key table entry first, then write the Foreign key entry using the new data from the Primary key table. If either fails, you rollback the transaction, otherwise you commit it.

I can't give exact details on the code, because it will be different for a stored procedure, or VB or C#...but Google will help you with the parts anyway.
 
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