注册 登录
编程论坛 ASP.NET技术论坛

关于用户登陆的问题

都督 发布于 2007-12-17 11:31, 1361 次点击
    string User = this.TextBoxUser.Text.ToString();
        string Pwd = this.TextBoxPwd.Text.ToString();
      
        if (User == "" | Pwd == "")
        {
            this.Label3.Visible = true;
            this.Label3.Text = "请输入用户名或密码";
        }
        else
        {
 SqlConnection myconn = new SqlConnection("Data Source=34-d248b3d2c78d;Initial Catalog=MMIS;User ID=sa;Password=4370532");
           myconn.Open();
            string mysql = "select * from memberInfo where 帐号= " + " ' " +User + " '" + "and 密码="+  "'"  + Pwd +  " ' ";//这句没错
          //  Response.Write(mysql);
          //  Response.End();
            SqlCommand mycmd = new SqlCommand(mysql, myconn);
            SqlDataReader mydr = mycmd.ExecuteReader();
           
            try
            {
                if (mydr.Read())
                {
                    Label3.Visible = true;
                    Label3.Text = "登录成功";
                }
                else
                {
                    Label3.Visible = true;
                    Label3.Text = "用户名或密码错误";
                }


             }
            finally
            {
                mydr.Close();
               
                myconn.Close();
            }
        }
         
         
为什么我输入正确的用户名和密码,但还是输出"用户名或密码错误"??? 为什么急呀
        



      
        

        
      
        

        
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        this.TextBoxUser.Text = "";
        this.TextBoxPwd.Text = "";
    }
}
8 回复
#2
huwei10242007-12-17 12:09
提示: 作者被禁止或删除 内容自动屏蔽,只有管理员可见
#3
都督2007-12-17 17:28
if (mydr.Read())
                {
                    Label3.Visible = true;
                    Label3.Text = "登录成功";
                }
#4
望雨成楼2008-02-16 11:47
这个只能说明你的数据读取有问题,你测试一下你是否真的能从数据库中获取到值!
#5
willam2008-02-16 17:37
看一下你的密码有没有加密的
#6
myjieli2008-02-18 12:53
你都没有到数据库里面查找,然后判断,肯定会出错啦!
#7
残影留香2008-03-26 16:27
你得返加三个值
#8
hebingbing2008-03-26 20:48
如果你的密码加密了那么"select * from memberInfo where 帐号= " + " ' " +User + " '" + "and 密码="+  "'"  + md5(Pwd) +  " ' ";
这样才能通过的。
#9
letian5842008-03-28 11:48
用这个方法呀
string sql="select id,user_name from 表 where name='"+this.TextBox1.text"';";
....
if(mydr.Read())
{
if(mydr.["pwd"].ToString==this.TextBox2.Text)
{
提示登陆成功!
}
else
{
提示密码错误!
}
}
else
{
提示用户不存在!
}
1