Retrieve Last Inserted Record In MySQL Database Using C#.NET
To get last inserted unique ID in MySQL, use LAST_INSERT_ID(). C# Code: 1 2 3 4 string insert_product_query = ( "INSERT INTO PRODUCTS (Stock) VALUES (5); SELECT LAST_INSERT_ID()" ); MySqlCommand cmd_query = new MySqlCommand(insert_product_query, objConn); int idResult = Convert.ToInt32(cmd_query.ExecuteScalar()); txtID.Text = idResult.ToString(); MySQL Docs: Getting Last Unique ID in MySQL