在此查询中,我应该更改哪些内容可以更新特殊用户名的角色名称?通过执行后的查询,每个角色名称都更新!!不考虑用户名!!我不希望那个请指导我。感谢
UPDATE
aspnet_Roles
SET
RoleName = @RoleName
FROM
aspnet_Membership
INNER JOIN
aspnet_Users ON aspnet_Membership.UserId = aspnet_Users.UserId
INNER JOIN
aspnet_UsersInRoles ON aspnet_Users.UserId = aspnet_UsersInRoles.UserId
INNER JOIN
aspnet_Roles ON aspnet_UsersInRoles.RoleId = aspnet_Roles.RoleId
WHERE
(aspnet_Users.UserName = @UserName)
答案 0 :(得分:0)
这是会员表,我找到了解决方案。这是:
sqlcmd = new SqlCommand("SELECT RoleId FROM aspnet_Roles where RoleName=@RoleName", sqlconn);
sqlcmd.Parameters.AddWithValue("@RoleName", "Reviewer");
sqlconn.Open();
System.Guid RoleId = ((System.Guid)sqlcmd.ExecuteScalar());
sqlcmd = new SqlCommand("SELECT UserId FROM aspnet_Users where UserName=@UserName", sqlconn);
sqlcmd.Parameters.AddWithValue("@UserName", EditorUserName);
System.Guid UserId = ((System.Guid)sqlcmd.ExecuteScalar());
sqlcmd = new SqlCommand("SELECT RoleId FROM aspnet_Roles where RoleName=@RoleName", sqlconn);
sqlcmd.Parameters.AddWithValue("@RoleName", "ReviewerEditor");
System.Guid ReviewerEditorRoleId = ((System.Guid)sqlcmd.ExecuteScalar());
sqlconn.Close();
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
sqlcmd = new SqlCommand("UPDATE aspnet_UsersInRoles SET RoleId = @RoleId WHERE (UserId= @UserId)", sqlconn);
sqlcmd.Parameters.AddWithValue("@RoleId", ReviewerEditorRoleId);
sqlcmd.Parameters.AddWithValue("@UserId", UserId);
sqlconn.Open();
sqlcmd.ExecuteNonQuery();
sqlconn.Close();