| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1659 人关注过本帖
标题:[求助]请高人们看看是什么问题
只看楼主 加入收藏
freedomGD
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-4
收藏
 问题点数:0 回复次数:23 
[求助]请高人们看看是什么问题
protected void Button1_Click(object sender, EventArgs e)
    {
        
        if (this.name.Text != "")//判断用户名是否未空
        {
         if (this.pwd.Text != "")//判断密码是否未空
         {
               if (this.yanzhen1.Text != "")//判断验证码是否未空
           {
            if (this.yanzhen1.Text == this.Label1.Text)//判断验证码是否相等
               {

                   try
                   {
                       OleDbConnection m_conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("./app_data/library.mdb"));
                       m_conn.Open();

                       OleDbCommand cmd = new OleDbCommand("select * from Administrator where 用户名=" + this.name.Text + "and 密码=" + this.pwd.Text, m_conn);    //建立sql查询语句

  int state = Convert.ToInt32(cmd.ExecuteScalar());           
                           if (state == 0 || state > 1)                              
                           {
                               this.Label2.Text = "用户不存在,请检测用户名和密码是否正确!";
                           }
                                  else
                                 {            this.Label2.Text = "登入成功!";              }
                          
                                
             m_conn.Close();}
              
                           catch (Exception a)
                               {    Response.Redirect("Default2.aspx");        }   
                           }
                  

            
                  else
                   {          this.Label2.Text = "验证码不正确,请重新输入!";         }   
                  }
            
             else
              {    this.Label2.Text = "验证码没有填写!";           }     
               }

        else
         {         this.Label2.Text = "密码没有填写!";                 }  
        }

程序是运行成功的,问题是只要验证码一样,用户名和密码和ACCESS表内的有无相同的数据,也可以到另一个网页,我是新手,请高人们看看是什么问题
搜索更多相关主题的帖子: void 密码 验证码 用户名 
2010-07-28 01:25
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
如果我没记错的话,ExecuteScalar方法应该是执行SQL语句,并返回记录结果中第一行第一列的值,你确定你的这个值一定是数字吗?况且看你的判断if (state == 0 || state > 1),你确定这个返回值只有1一个吗?难道你有这样一个字段,它的值都是1,然后这个字段是表的第一列?并且我还想问一下,你的这个程序是用记事本写的吗?

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-28 09:48
Alohal
Rank: 2
等 级:论坛游民
帖 子:14
专家分:22
注 册:2010-7-28
收藏
得分:0 
ExecuteScalar方法是返回首行首列,而你用的select *,这显然不对嘛,应该select count(*)才是返回查找记录数,而且你那个state怎么还是>1,莫非查找出来的记录不唯一,一个名字加一密码不是完全能确定唯一记录么。你再改改试试。
2010-07-28 11:10
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
程序代码:
protected void Button1_Click(object sender, EventArgs e)
        {
            #region 条件判断

            if (string.IsNullOrEmpty(this.name.Text))//判断用户名是否未空
            {
                this.Label2.Text = "用户名有填写!";
                return;
            }
            if (string.IsNullOrEmpty(this.pwd.Text))//判断密码是否未空
            {
                this.Label2.Text = "密码没有填写!";
                return;
            }
            if (string.IsNullOrEmpty(this.yanzhen1.Text))//判断验证码是否未空
            {
                this.Label2.Text = "验证码没有填写!";
                return;
            }
            if (!this.yanzhen1.Text.Equals(this.Label1.Text))//判断验证码是否相等
            {
                this.Label2.Text = "验证码不正确,请重新输入!";
                return;
            }

            #endregion

             OleDbConnection m_conn = null;
             try
             {
                 m_conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("./app_data/library.mdb"));
                 m_conn.Open();

                 OleDbCommand cmd = new OleDbCommand("select COUNT(*) from Administrator where 用户名='" + this.name.Text + "' and 密码='" + this.pwd.Text + "'", m_conn);    //建立sql查询语句

                 int state = Convert.ToInt32(cmd.ExecuteScalar());
                 if (state != 1)
                 {
                     this.Label2.Text = "用户不存在,请检测用户名和密码是否正确!";
                 }
                 else
                 {
                     this.Label2.Text = "登入成功!";
                 }
             }

             catch (Exception a)
             {
                 Response.Redirect("Default2.aspx");
             }
             finally
             {
                 if (m_conn != null)
                 {
                     m_conn.Close();
                 }
             }
        }


[ 本帖最后由 bygg 于 2010-7-28 11:43 编辑 ]

飘过~~
2010-07-28 11:38
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
Alohal你要注意到一个问题,他的页面跳转实际上是因为代码出现异常才会跳转的,而异常的问题是由于他的sql语句有问题
OleDbCommand cmd = new OleDbCommand("select * from Administrator where 用户名=" + this.name.Text + "and 密码=" + this.pwd.Text, m_conn);    //建立sql查询语句
int state = Convert.ToInt32(cmd.ExecuteScalar());
显然是他在加查询条件的时候没有加单引号引起的

楼主请注意,你的sql那句应该这样写
OleDbCommand cmd = new OleDbCommand("select count(*) from Administrator where 用 户名='" + this.name.Text + "' and 密码='" + this.pwd.Text +"'", m_conn);

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-28 11:40
Alohal
Rank: 2
等 级:论坛游民
帖 子:14
专家分:22
注 册:2010-7-28
收藏
得分:0 
回复 5楼 冰镇柠檬汁儿
恩,就是SQL语句没加单引号,呵呵,我都没注意了。
2010-07-28 11:55
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
回复 6楼 Alohal
没什么的,bygg也没注意到呢

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-28 11:56
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
谁说我没注意,哼哼/

飘过~~
2010-07-28 12:02
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
以下是引用bygg在2010-7-28 12:02:59的发言:

谁说我没注意,哼哼/
改帖子是有时间记录的哦

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-07-28 13:15
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
.其实我是注意到的,不过把前面那个改了,后面就忘记了直接发了,后面发现了,却在你发贴之后.
就这样

飘过~~
2010-07-28 13:18
快速回复:[求助]请高人们看看是什么问题
数据加载中...
 
   



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

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