Retrieve Last Inserted Record In MySQL Database Using C#.NET
To get last inserted unique ID in MySQL, use LAST_INSERT_ID().
C# Code:
MySQL Docs: Getting Last Unique ID in MySQL
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(); |
Comments
Post a Comment