c# - Catch Id (INT AUTO INCREMENT) of a Record after INSERT INTO Statement -


This is my first time that I use MySQL as a datestouse for my C # application, as I I have seen that there is no irregularity type as I decieded for INTI_INCREMENT to use INT in SQL Server, my problem is now if I execute INSERT, how can I add the record ID now?

My quick and dirty solution has been performed, execute a selection MAX (ID) from the table description but it does not seem consistent. I believe that there is a better solution like mysql_insert_id () (PHP).

Any ideas how to solve it in C #?

You use the function last_int_id () < / Code>:

  select last_insert_id ()  

You have to use this database session, that is, the same connection object.

As you've thought, you should not use max (id) to get the ID, because it will get the final ID created from any session, it No specific sessions. If two concurrents are closed for different users over time (so both entries are before one of them before choosing to receive the ID), they will get the last entry ID.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -