I was just about to post asking how to do this when I stumbled across the solution. All my research on the web suggests that the only way is to use stored procedures with an output parameter. Unfortunately, my queries are necessarily dynamically generated, and output parameters do not work with text commands on MySQL. (I wont go into the cause of that issue here, but it is well documented online.)
I did manage to find that the class MySql.Data.MySqlClient.MySqlCommand actually contains the last_insert_id()
as a property. So I was able to write code in my datasource Inserted
event like this...
protected void datasource_Inserted(object sender, SqlDataSourceStatusEventArgs e)
{
int newID = ((MySqlCommand)e.Command).LastInsertedId;
}
Anyway, since it took me a while to find, I thought I'd post this here to try and help someone else who may be having the same problem.
Cheers
/H