最後に挿入されたIDを取得する方法?
私はこのコードを持っています: string insertSql = "INSERT INTO aspnet_GameProfiles(UserId,GameId) VALUES(@UserId, @GameId)"; using (SqlConnection myConnection = new SqlConnection(myConnectionString)) { myConnection.Open(); SqlCommand myCommand = new SqlCommand(insertSql, myConnection); myCommand.Parameters.AddWithValue("@UserId", newUserId); myCommand.Parameters.AddWithValue("@GameId", newGameId); myCommand.ExecuteNonQuery(); myConnection.Close(); } このテーブルに挿入すると、auto_increment int主キー列と呼ばれGamesProfileIdますが、この後に最後に挿入されたものを取得して、そのIDを使用して別のテーブルに挿入するにはどうすればよいですか?