Använda LastInsertId

Modified on 2019/09/05 14:02 by Jovall — Categorized as: Uncategorized

asp.net sqldatasource last_insert_id

After spending nearly a whole day trying to figure this out, i have stumbled across a solution. All the articles I found on the web rely on using stored procedures to get the output parameters working (which is not an option in my circumstance).

However, there are some nice .net classes available to add to your solution as references: MySql.Data.MySqlClient Using this will allow you to convert the datasource command object to a MySqlCommand object, which has the LastInsertedId property.

eg: in the DataSource_Inserted event, write
int newID = ((MySqlCommand)e.Command).LastInsertedId;

Hearth_Stone