Catch Id (INT AUTO INCREMENT) of a Record after INSERT INTO Statement
Posted
by Johannes
on Stack Overflow
See other posts from Stack Overflow
or by Johannes
Published on 2009-12-06T18:32:33Z
Indexed on
2010/03/28
17:53 UTC
Read the original article
Hit count: 226
This is my first time I use MySQL as datastorage for my C# Application, as I've seen that there is no UNIQUEIDENTIFIER type as in SQL server I decieded to use INT with AUTO_INCREMENT, my problem is now if I execute a INSERT, how may I get the ID of the Record I just added.
My quick and dirty solution has been to execute a SELECT MAX(ID) FROM table Statement. But this doesn't seem consistent. I belive there is a better solution something like mysql_insert_id() (PHP).
Any Idea how to resolve this in C#?
© Stack Overflow or respective owner