Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone.

I am developing a application in c# where you insert values from textboxes to two different MYSQL tables. In table 1 I have a employeeid which is auto incremented when a new record is created. In table 2 I have a field of the same name and I want to assign it the corresponding id from table1. I'm not sure how to do this. Do I use a join??

Any advice would be very much appreciated
Posted
Comments
ZurdoDev 8-Apr-13 17:00pm    
I believe in MySQL LAST_INSERT_ID() will give you the last ID. So, if you had 2 insert statements, after the first one which inserts into table1 store LAST_INSERT_ID() into a variable and then use that variable to insert into table 2.
Member 9611735 8-Apr-13 17:52pm    
You are wonderful! thank you, your solution works a treat
ZurdoDev 9-Apr-13 7:30am    
Good to hear. I'll post it as a solution then.

1 solution

I believe in MySQL LAST_INSERT_ID() will give you the last ID. So, if you had 2 insert statements, after the first one which inserts into table1 store LAST_INSERT_ID() into a variable and then use that variable to insert into table 2.
 
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