MySQL
を DBMS としたソフトウェアを現在開発中です。
先日のことですが、Auto Increment な Primary Key のテーブルにレコードをインサートした時、自動的に設定された Primary Key の値を取得する方法がわかりませんでした。
ということでメモとして残しておくことにします。
以下のような SQL文字列を、MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar() メソッドで実行して値を取得するだけです。
INSERT HOGEHOGE_TABLE VALUES(null, "Rさん格好いい"); SELECT LAST_INSERT_ID()
ちょっと悩んでしまった。