Thursday, June 23, 2011

Retrieving Last Inserted ID From MYSQL from C#

After inserting a record into the database, to retrieve the ID created on the insert, use the following code:

OdbcCommand1.CommandText="SELECT LAST_INSERT_ID()";

Int64 LastID;
LastID = Convert.ToInt64(OdbcCommand1.ExecuteScalar());

No comments:

Post a Comment