Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL table Help
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 8-Apr-13 10:57am
Comments
ryanb31 at 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 at 8-Apr-13 17:52pm
   
You are wonderful! thank you, your solution works a treat
ryanb31 at 9-Apr-13 7:30am
   
Good to hear. I'll post it as a solution then.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100