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

如何获得最后插入的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 关注
  • 630 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号