0

我应该在此查询中进行哪些更改以更新特殊用户名的角色名称?通过执行后的查询,每个角色名称都更新了!!不考虑用户名!!我不想这样,请指导我。谢谢

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)
4

1 回答 1

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();
于 2012-11-19T08:47:30.170 回答