| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 836 人关注过本帖
标题:为什么老是显示登录失败?
只看楼主 加入收藏
fylnlx
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2009-3-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
为什么老是显示登录失败?
protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = WebConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            conn.Open();
            SqlCommand cmd = new SqlCommand("select [name],password from te", conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds,"te");
            SqlDataReader dr = cmd.ExecuteReader();
            string name = Convert.ToString(dr);
            dr.Close();
            SqlDataReader dr1 = cmd.ExecuteReader();
            string password = Convert.ToString(dr1);
            Response.Write(name);
            if(txtName.Text.ToString()==name&&txtPassword.Text.ToString()==password)
            {
                Response.Write("登录成功");
            }
            else
            {
                Response.Write("登录失败");
            }
            dr1.Close();
            conn.Close();
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.txtName.Text = "";
            this.txtPassword.Text = "";
        }
    }
搜索更多相关主题的帖子: 失败 登录 
2009-09-01 22:39
dhbest
Rank: 2
等 级:论坛游民
帖 子:55
专家分:89
注 册:2008-10-31
收藏
得分:10 
  SqlCommand cmd = new SqlCommand("select [name],password from te", conn);
  SqlDataReader dr = cmd.ExecuteReader();
  string name = Convert.ToString(dr);
  dr.Close();
  SqlDataReader dr1 = cmd.ExecuteReader();
  string password = Convert.ToString(dr1);

这里得出来的name,password都是sql语句查出来的[name],password 的值 ,然后又跟txtbox的值比较肯定是不相同的!
     你可以在查询语句后加个条件  “select [name],password from te where [name] = '"+txtName.Text.ToString()+"' and password = '"+txtPassword.Text.ToString()+"'”   如果有结果则成功否则失败!
2009-09-02 15:23
xiaobin9015
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:36
专家分:154
注 册:2009-9-2
收藏
得分:10 
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = WebConfigurationManager.ConnectionStrings["Conn"].ConnectionString;
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from te", conn);
            SQlDataReader dr = cmd.ExecuteReader();
            string name;
            string password;
            while(dr.Read())
            {
             name=(string)dr["用户名"];
             password=(string)dr["密码"];
            if(txtName.Text.ToString()==name&&txtPassword.Text.ToString()==password)
            {
                Response.Write("登录成功");
            }
            else
            {
                Response.Write("登录失败");
            }
            }
2009-09-02 17:37
visolleon
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:71
专家分:182
注 册:2007-1-16
收藏
得分:0 
调试看看,不要老看你自己输出的内容! 看看有没有Exception

2009-09-05 22:35
bozl
Rank: 2
等 级:论坛游民
帖 子:49
专家分:53
注 册:2007-10-23
收藏
得分:0 
sql语句
SqlCommand cmd = new SqlCommand("select count(*) from te where name="+txtName.Text.ToString()+" and "+"password="+txtPassword.Text.ToString(), conn);

魔の左手............
神の右手.............
2009-09-07 14:20
daygujun
Rank: 1
等 级:新手上路
帖 子:2
专家分:5
注 册:2009-9-7
收藏
得分:0 
我的建议先是:你使用存储过程.
另外把包错情况说出来.
2009-09-07 22:08
aganarRMJ
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:27
专家分:160
注 册:2009-9-10
收藏
得分:0 
语句显得很乱,你可以把用户和密码的值当做参数传递到SQL内,作为查询的一种条件,让返回的数据集为顶多只含有一条记录,在来一个试探该数据集是否有内容判断登录成功与否就大功告成了的!
2009-09-10 16:42
xudongcsharp
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:129
专家分:156
注 册:2009-5-31
收藏
得分:0 
楼上正解
2009-09-11 09:44
快速回复:为什么老是显示登录失败?
数据加载中...
 
   



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

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