title: How to get last inserted id?
body: <p>I have this code:</p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>When I insert into this table, I have an auto_increment int primary key column called <code>GamesProfileId</code>, how can i get the last inserted one after this so I can use that id to insert into another table?</p>