Click here to Skip to main content
15,789,952 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All, i need an help on setting / permitting options to users for the forms
to display, i have an Application with more than 5 forms which is called from
the menu strip, the users will login with the valid username and password stored in SQL 2008 server, i have to set for user1 and user2 should be able to view only form1 and form2.
Please help on getting into this, the Admin login user can set the options for the users, how do i store the permissions for the users in SQL

Advanced thanks

One way to do this would be to set the permissions on the form in which the menus exist. Then you could do something like: (very simplistic code)

int userPermission = [get_user_permission_level];

if (userPermission == 1)
    mnuItem1.visible = true;
    mnuItem2.visible = false;
else if (userPermission == 2)
    // ...

// and so on as required.

You'll need to work out how to do this in a more sophisticated way but this should get you going.

In terms of storing the permissions in the database presumably your schema has a table that describes the users? Add a column in there that holds the permissions level and this might be a reference to a table that holds a list of permission levels.
Share this answer
jaipe 24-Feb-11 8:41am    
Thanks for the info
Started working on it, will get back to you
You can create a table with usernames and access levels.

ie username varchar(50) and level int

Query this table in login and according to the level dispose the menuitems that link to the forms that you don't want to give access to.

Assign a level to all users.
Share this answer
jaipe 24-Feb-11 8:45am    
Thank you, i have added one more column as (Permit) int to the table... i am bit confused on how to proceed, below is the code which i am using on button login click

private void btnLogon_Click(object sender, EventArgs e)
SqlConnection cn = SRData.DRSQLConnection.Instance;
catch (Exception er)
SqlDataAdapter objAdpt = new SqlDataAdapter();
DataTable objDt = new DataTable();
objAdpt.SelectCommand = new SqlCommand("select * from users where username = @username AND password = @password", cn);
objAdpt.SelectCommand.Parameters.AddWithValue("@username", txtUserName.Text.Trim());
objAdpt.SelectCommand.Parameters.AddWithValue("@password", txtPassword.Text.Trim());
if (objDt.Rows.Count > 0)

MessageBox.Show("Username/Password Wrong", "Credentials Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

milenalukic 24-Feb-11 10:07am    
Good so far - just one little bit more!

When you call your main form below you need to pass in the permit parameter


When loading Scribe_Reports you need to remove the menuitems according to the permit level. Best practice would be using SWITCH(permit) CASE code;

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