Getting auto-generated PK value back
Posted by: David Thielen
Date: November 12, 2006 04:39PM

I was told in another post that after inserting a row with an autogenerated PK, I can get the PK value back using LAST_INSERT_ID() or mysql_insert_id().

Is the way to do this:
cmd.CommandText = "insert into Schedule (sTitle, sDescription) values ('my sched', 'all about it'); LAST_INSERT_ID()";
object rtn = cmd.ExecuteScalar();
return (long)(decimal)rtn;

thanks - dave

ps - I am asking instead of trying because I am still waiting on the DBA to convert our schema from SqlServer to MySql (is there a tool that does this other than ErWin? Something not a fortune so I can get it for myself and not have to wait?).

Options: ReplyQuote


Subject
Written By
Posted
Getting auto-generated PK value back
November 12, 2006 04:39PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.