Reputation: 2535
I've got the following table in MySql: Contact:
Now, I'm writing an INSERT INTO in my c# program, but the Id column is defined to auto increment, so my statement looks like this: INSERT INTO Contact (Name, FirstName) VALUES ("Sander", "Declerck")
So how can I get the new value for my object?
Upvotes: 1
Views: 1384
Reputation: 37761
In MySQL, you can use SELECT LAST_INSERT_ID(), or your API wrapper might let you call mysql_insert_id().
Upvotes: 1
Reputation: 425391
Issue this query:
SELECT LAST_INSERT_ID()
right after the INSERT
.
Upvotes: 2