| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 440 人关注过本帖
标题:登录问题,新手,谢谢大家了!
只看楼主 加入收藏
hryna
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
登录问题,新手,谢谢大家了!
做了一个登录窗体,根据两张用户表实现登录,分别是admin和user,当为admin时可以看到主窗体中的所有菜单项,user时只能看到部分。代码写完了之后运行没有问题,admin的登录功能也能正确实现,只是当用user身份登录时,总提示下面代码中的‘user'附近有错误(红色标出)。请高手帮我看一下,问题出在哪,谢谢大家了!不好意思,目前只有20分了。
        private void bt_login_Click(object sender, EventArgs e)
        {
            switch (comidentity .Text)
            {
                case "管理员":
                    string g_sql = string.Format("select count(*) from admin where AdminName='{0}' and AdminPwd='{1}'", txtname.Text, txtpwd.Text);
                    SqlCommand g_comm = new SqlCommand(g_sql, DBClass.conn);
                    DBClass.conn.Open();
                    int count=(int)g_comm.ExecuteScalar();
                    if (count == 1)
                    {
                        DBClass.indentity = "管理员";
                        this.Visible = false;
                        frmMain frm_main = new frmMain();
                        frm_main.Show();
                    }
                    else
                    {
                        n = n + 1;
                        if (n < 3)
                        {
                            MessageBox.Show("您的用户名或密码不正确,请重试!");
                            txtname.Text = "";
                            txtpwd.Text = "";
                            comidentity.SelectedIndex = -1;
                            txtname.Focus();
                        }
                        else
                        {
                            MessageBox.Show("错误次数已达三次,请联系管理员");
                            Application.Exit();
                        }
                    }
                    DBClass.conn.Close();
                    break;

                case "普通用户":
                    string p_sql = string.Format("select count(*) from user where username='{0}' and userpwd='{1}'", txtname.Text, txtpwd.Text);
                    SqlCommand p_comm = new SqlCommand(p_sql, DBClass.conn);
                    DBClass.conn.Open();

                    int result = (int)p_comm.ExecuteScalar();
                    if (result == 1)
                    {
                        DBClass.indentity = "普通用户";
                        this.Visible = false;
                        frmMain frm_main = new frmMain();
                        frm_main.Show();
                    }
                    else
                    {
                        n = n + 1;
                        if (n < 3)
                        {
                            MessageBox.Show("您的用户名或密码不正确,请重试!");
                            txtname.Text = "";
                            txtpwd.Text = "";
                            comidentity.SelectedIndex = -1;
                            txtname.Focus();
                        }
                        else
                        {
                            MessageBox.Show("错误次数已达三次,请联系管理员");
                            Application.Exit();
                        }
                    }
                    DBClass.conn.Close();
                    break;
            }
        }
搜索更多相关主题的帖子: 20分 private 管理员 admin 
2011-09-03 15:03
aspic
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:51
帖 子:2258
专家分:8050
注 册:2008-2-18
收藏
得分:20 
[user]
2011-09-03 16:12
hryna
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-9-3
收藏
得分:0 
谢谢,已经解决了。
2011-09-03 16:45
刘杰明
Rank: 8Rank: 8
来 自:山东大学威海校区
等 级:蝙蝠侠
帖 子:155
专家分:872
注 册:2011-6-20
收藏
得分:0 
。。。

______________________________加油__!__!___!
2011-09-06 20:16
WHHCNN
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-10-17
收藏
得分:0 
能告诉我怎么解决的么
2011-10-26 10:59
快速回复:登录问题,新手,谢谢大家了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051310 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved