Bug #26139 | MySqlCommand.LastInsertedId doesn't work for stored procedures | ||
---|---|---|---|
Submitted: | 7 Feb 2007 8:57 | Modified: | 21 Jan 2014 23:07 |
Reporter: | Gert Brigsted | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 5.0.27 | OS: | Windows (Windows XP Pro) |
Assigned to: | CPU Architecture: | Any | |
Tags: | Connector/Net, LastInsertedId, MySqlCommand |
[7 Feb 2007 8:57]
Gert Brigsted
[10 Feb 2007 7:46]
Paolo Niccolò Giubelli
Try with this: MySqlConnection conn = new MySqlConnection("foobar"); MySqlCommand cmd = new MySqlCommand("testproc", conn); cmd.CommandType = CommandType.StoredProcedure; //To add: MySqlParameter pId = new MySqlParameter("?_ID",MySqlDbType.Int32); pId.Direction = System.Data.ParameterDirection.Output; cmd.Parameters.Add(pId); cmd.Parameters.Add("?_Name", "testperson"); conn.Open(); cmd.ExecuteNonQuery(); //It's better to close the connection before you dispose it conn.Close(); conn.Dispose(); //Get back your id *using a cast* int id = (int)pId.Value; Response.Write(id.ToString());
[13 Feb 2007 22:16]
Reggie Burnett
This is a server bug. Currently, MySQL doesn't properly return generated keys or update counts from a stored procedure. If that is needed, you will need to use SELECT last_insert_id() into an output param. I've added a test case to our test suite and will enable it when this is fixed in the server.
[13 Feb 2007 22:18]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/19808
[13 Feb 2007 22:19]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/19809