Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
"DELETE FROM Roles WHERE RoleId =@RoleId AND UserId = (SELECT u.UserId FROM Users u WHERE u.UserName = @UserName"


i want to get role id from database

for u.username i have a textbox in my project and use where clause for that.. what i can do to get roleid for particular user form database...
Posted

I'd be thinking something simple like
Select RoleID from Roles where UserID = @Username


Note - I haven't validated the user against the Users table - I am asuming that was done when the role was added. But if we wanted to then I would go with this

Select RoleID from Roles R, Users U 
where R.UserID = U.UserID
and   UserID = @Username
 
Share this answer
 
This would fetch you the users and roles:
SQL
select rp.name as database_role, mp.name as database_user
from sys.database_role_members drm
join sys.database_principals rp on (drm.role_principal_id = rp.principal_id)
join sys.database_principals mp on (drm.member_principal_id = mp.principal_id)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900