Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 2 tables table 1 and table 2
table 1 has primary key and identity
table 2 has foreign key no identity
how to insert data in both the tables at once
Posted
Comments
Jeet Gupta 17-Feb-15 0:47am    
can you provide your table structure.
for inserting records in both the table you can use procedure.
better you provide more information.
Jeet Gupta 18-Feb-15 2:16am    
if you familiar with stored procedure then i suggest you to use stored procedure.
for inserting record in both the table you have to use two procedures.
In first procedure write insert query for first table and also return the Identity column value of the inserted record so that when you call the second procedure to insert record in the second table you can pass the returned identity column value to the second table.

1 solution

i solved it with sql injection but it can also be done with parameterize query and it is recomended
 
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