A. Hamdi A. Hamdi - 4 months ago 17x
MySQL Question

whats the right version for using either scope_identity() ,@@identity (),last_insert_id() in mysql

im working on asp.net c# ,i tried all 3 of them but none worked ,
this is the sql error(You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()')
this is my query:

String st = ("INSERT INTO `service` VALUES ('','" + noms + "','" + Desc + "','3','" + ad + "','" + vil + "','" + pays + "')"+" SELECT SCOPE_IDENTITY()");


You can use LastInsertedId property of MySqlCommand like this :

// cmd is MySqlCommand objet
long lastInsertedId = cmd.LastInsertedId;