| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7896 人关注过本帖, 1 人收藏
标题:求一个c#登陆系统代码
只看楼主 加入收藏
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
你能告诉我下连接数据库哪个关键字都是什么意思么
什么时候用
用的时候都需要哪些参数
2008-11-18 16:50
dwwwing
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:284
专家分:986
注 册:2008-10-11
收藏
得分:0 
public static void ExecuteNoQuery(string sql, SqlParameter[] parms)
        {
            using (SqlConnection connection = new SqlConnection())
            {
                connection.ConnectionString = connectionString;
                connection.Open();

                SqlCommand cmd = connection.CreateCommand();
                = CommandType.StoredProcedure;
                = sql;

                if (parms != null)
                {
                    cmd.Parameters.AddRange(parms);
                }
                cmd.ExecuteNonQuery();
            }

        }
2008-11-18 22:25
dwwwing
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:284
专家分:986
注 册:2008-10-11
收藏
得分:0 
呵呵,忘记说明连接字符串了,connectionString = "你要连接的数据库字符串"
2008-11-18 22:27
artietao
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-11-19
收藏
得分:0 
研究下~正在学习中...
2008-11-21 10:24
梦心
Rank: 4
来 自:福建平和
等 级:贵宾
威 望:13
帖 子:1910
专家分:0
注 册:2007-5-11
收藏
得分:0 

这帖子还顶得真长

我清高和我骄傲的倔强,在风中大声的唱:我不听,我不听~~做我自己最特别,呼呼~~啦啦~~~
我的博客园地址: [url]http://[/url]
2008-11-21 11:14
谁与争瘋
Rank: 2
等 级:论坛游民
帖 子:360
专家分:14
注 册:2008-11-18
收藏
得分:0 
是啊 我们要有耐心啊

这些未来可都是中国软件产业的核心人物哦

2008-11-21 15:37
likun123
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-11-21
收藏
得分:0 
正好我项目有这个,我随手粘贴过来吧,这个论坛真好,以后常来!


     //确定 按钮事件处理
        private void btok_Click(object sender, EventArgs e)
        {

            if (panduan())   //调用panduan方法
            {
                showUser();
            }
        }


        //退出 按钮事件处理
        private void btexit_Click(object sender, EventArgs e)
        {
            help.tuichu();

        }


        //登陆判断方法
        private bool panduan()
        {
            if (txtLoginId.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户名", "登陆提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginId.Focus();             //光标定义位置
                return false;
            }
            else if (txtLoginPwd.Text.Trim() == "")
            {
                MessageBox.Show("请输入密码", "登陆提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtLoginPwd.Focus();
                return false;
            }
            else if (cboLoginType.Text.Trim() == "")
            {
                MessageBox.Show("请选择登陆类型", "登陆提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            else
            {
                return true;
            }
        }


        //登陆类型方法
        public void showUser()
        {

            switch (cboLoginType.Text)
            {
                case "管理员":
                    try
                    {
                        Admin();                    //管理员权限
                        this.Visible = false;    //隐藏登陆窗体
                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.Message.ToString());

                    }
                    finally
                    {
                        DBHelper.connection.Close();                //关闭数据库
                    }
                    break;
                case "学员":
                    try
                    {
                        xuesheng();                 //学生权限
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());

                    }
                    finally
                    {
                        DBHelper.connection.Close();                //关闭数据库
                    }
                    break;
            }
        }

        //管理员属性
        private void Admin()
        {
                //数据库连接
                DBHelper.connection.Open();
                //创建sqlcommand对象去执行命令
                string sql = string.Format("select count(*) from AdminLogin where AdminrName='{0}' and AdminPwd='{1}'",
                    this.txtLoginId.Text, this.txtLoginPwd.Text);
                //执行命令
                SqlCommand sqlcom = new SqlCommand(sql, DBHelper.connection);
                int result = (int)sqlcom.ExecuteScalar();
                if (result != 0)
                {
                    help.user = this.txtLoginId.Text.Trim();            //把用户名字保存help类
                    help.Type = this.cboLoginType.Text.Trim();          //把登录类型保存help类
                    Form_Main Main = new Form_Main();
                    Main.Show();
                    this.Visible = false;
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!请重新输入");
                }
            }   
        



        //学员属性
        private void xuesheng()
        {
                //查询语句
                string sql = string.Format("select count(*) from StuInfo where StuNO='{0}' and StuPwd='{1}'", this.txtLoginId.Text.Trim(), this.txtLoginPwd.Text.Trim());
                SqlCommand command = new SqlCommand(sql, DBHelper.connection);      //创建 SqlCommand 对象
                DBHelper.connection.Open();   //打开数据连接
                int num = (int)command.ExecuteScalar();           //执行命令
                if (num != 0)
                {
                    help.Type = this.cboLoginType.Text.Trim();
                    help.user = this.txtLoginId.Text.Trim();
                    Form_Main Main = new Form_Main();
                    Main.Show();
                                   
                }
                else
                {
                    MessageBox.Show("用户名或密码错误!请重新输入");
                }
        }
2008-11-21 22:54
andy560225
Rank: 1
来 自:天上
等 级:新手上路
帖 子:72
专家分:0
注 册:2008-10-29
收藏
得分:0 
你也不看看是谁发的帖子
能不长么.

我知道我笨,可是我很勤劳
妈妈说:"早起的鸟有虫吃"!
2008-11-22 11:19
duanzelong
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-11-22 13:51
goodrenze
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-8-22
收藏
得分:0 
果然是卧虎藏龙之地啊。
我终于找到了个学习编程的好地方,以后常来逛。
O(∩_∩)O哈哈~
2008-11-22 21:25
快速回复:求一个c#登陆系统代码
数据加载中...
 
   



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

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