OddCactus 发表于 2015-1-2 17:43:18

根据登录用户角色设置不同权限!!马上答辩了!求改!!

在登陆页面写了一个全局变量 user_name 用来接收登录用户的用户名
在主页面的状态栏显示登陆页面的用户名
然后我现在想在主页面通过用户名获取数据库表里的相应角色 再根据不同角色设置不同权限
一直报错
求大神修改
或者还有什么比较好的方法可以实现我的需求!!后天就答辩了!急哭!!!

private void main_form_Load(object sender, EventArgs e)
      {
            string conStr = "server=.;database=bug_manage;Trusted_Connection=SSPI";
            SqlConnection con = new SqlConnection();
            con.ConnectionString = conStr;

            string showname = login_form.user_name;
            this.toolStripStatusLabel2.Text = "当前用户:" + showname;
            
string sql = "select * from in_staff where p_name='" + login_form.user_name + "'";
            con.Open();
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader sdr = cmd.ExecuteReader();
            string role = sdr.GetValue(3).ToString();
            if (role == "项目经理")
            {
                toolStripButton1.Visible = false;//上传
                toolStripButton10.Visible = false;//测试
                toolStripButton9.Visible = false;//修复
                文件FToolStripMenuItem.Visible = false;//系统维护
            }
            else if (role == "测试人员")
            {
                文件FToolStripMenuItem.Visible = false;
                toolStripButton1.Visible = false;
                toolStripButton3.Visible = false;
                toolStripButton9.Visible = false;
               
            }

OddCactus 发表于 2015-1-2 17:44:09

14行老是报错!!

ibcadmin 发表于 2015-1-3 15:19:24

14行的getValue(3) 检查是否有第3个数据报的错是不是索引超出范围?或空对象?
页: [1]
查看完整版本: 根据登录用户角色设置不同权限!!马上答辩了!求改!!