为了账号安全,请及时绑定邮箱和手机立即绑定

如何获得最后插入的id?

如何获得最后插入的id?

SMILET 2019-06-17 17:23:30
我有个密码: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?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 606 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信