我有個密碼: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();}當我插入這個表時,我有一個自動遞增的int主鍵列,名為GamesProfileId,如何在此之后獲得最后插入的一個,以便使用該id插入另一個表?如何獲得最后插入的id?
添加回答
舉報
0/150
提交
取消