c# - Stored procedure dynamic where clause, getting a value from a variable -


i'm using sql server, c#, asp.net. doing project menus dynamically displayed database according user's permission. of here's stored procedure,

create proc spgetmenudata begin  select * tblmenu1 end 

i have users table, roles table , menu table on database. users: userid, username, pass, roleid roles: roleid, name (admin, user) menu: menuid, name, url, roleid, userid or menuid, name, url, roleid (please tell me if what's more appropriate) now, want userid , roleid check menus. can store userid variable program , pass stored procedure. like:

create proc spgetmenudata begin  select * tblmenu1 //(where tblmenu1.userid = useridfromthevariable , tblmenu1.roleid = useridfromthevariable's roleid) end 

please me, i'm beginner. in advance!

here do:
users table: user_id, username, pass, role_id
roles table: role_id, role_name
menu_roles table: role_id, menu_id
menus table: menu_id, name, url
specify menus belong role , have roles belong users.
menu_id, name, , url given user:

create procedure getmenus     @someusername       set nocount on;     select menu_id, name, url menus menu_id      in (select menu_id users  join menu_roles on users.role_id=menu_roles.role_id username=@someusername) go 

Comments

Popular posts from this blog

javascript - Wordpress slider, not displayed 100% width -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -