| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 944 人关注过本帖
标题:C#登录验证的问题
只看楼主 加入收藏
foxsc
Rank: 2
等 级:论坛游民
帖 子:56
专家分:17
注 册:2007-4-9
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:4 
C#登录验证的问题
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
                MessageBox.Show("用户名不能为空");
            else
            if (textBox1.Text == "")
                MessageBox.Show("请输入密码");
            string name = comboBox1.Text.Trim();
            string password = textBox1.Text.Trim();
            string path = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            path += @"\1.mdb";
            string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + path;
            OleDbConnection conn = new OleDbConnection(constr);
                       conn.Open();
                       OleDbCommand cmd = new OleDbCommand();
                        = "select * FROM DB_user where user_id='" + name + "' and password='" + password + "'";
                  
    Int32 count = Convert.ToInt32(cmd.ExecuteScalar()); //提示说未初始化……
            

            if (count>0)
            {
                MessageBox.Show("OK");
            }
            else
            {
                MessageBox.Show("NO");
            }
            
        }


   Int32 count = Convert.ToInt32(cmd.ExecuteScalar()); //提示说未初始化……
   请各位给看看,教教小弟,看看是哪里的问题
搜索更多相关主题的帖子: 登录 验证 
2009-09-12 14:29
foxsc
Rank: 2
等 级:论坛游民
帖 子:56
专家分:17
注 册:2007-4-9
收藏
得分:0 
private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
                MessageBox.Show("用户名不能为空");
            else
            if (textBox1.Text == "")
                MessageBox.Show("请输入密码");
 
            string name = comboBox1.Text.Trim();
            string password = textBox1.Text.Trim();
 
            string path = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
            path += @"\1.mdb";
            string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + path;
            OleDbConnection conn = new OleDbConnection(constr);
            conn.Open();
            OleDbCommand command = new OleDbCommand("select * FROM DB_user where user_id='" + name + "' and password='" + password + "'", conn);
            OleDbDataReader read = command.ExecuteReader();
            read.Read();
 
            if (read.HasRows)
            {
                MessageBox.Show("OK");
            }
            else
            {
                MessageBox.Show("NO");
            }

        }

 OleDbDataReader read = command.ExecuteReader();
这里也提示类型不匹配,我都搞晕了
如何转换呢?

人生漫漫,何淡了断,向前走过去,是个艳阳天,遗忘过去,意味着背叛,不要空许什么愿,不说爱你一万年
2009-09-12 15:01
foxsc
Rank: 2
等 级:论坛游民
帖 子:56
专家分:17
注 册:2007-4-9
收藏
得分:0 
已经解决,是因为Password,在数据库中我用的是数值型,导致出错……
在此谢过各位帮助过我的朋友

人生漫漫,何淡了断,向前走过去,是个艳阳天,遗忘过去,意味着背叛,不要空许什么愿,不说爱你一万年
2009-09-12 15:36
jinwushe
Rank: 2
等 级:论坛游民
帖 子:19
专家分:40
注 册:2009-5-6
收藏
得分:14 
目前只知道SQL
2009-09-13 17:20
nmgkd123
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-4-11
收藏
得分:0 
这个是什么 问题  啊,不咋懂
2010-04-11 16:41
快速回复:C#登录验证的问题
数据加载中...
 
   



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

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