Click here to Skip to main content
12,068,520 members (66,340 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# MySQL table
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 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
ryanb31 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2016
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