wangxiaoenen 2015-08-31 02:24 采纳率: 0%
浏览 5507

asp.net中登录页面用户名和密码与数据库中数据进行比对出错,求大神指导!!!!

dr['AID']=112100011TextBox1.Text=1121000177
dr['apassword']=245fghTextBox2.Text=123456
dr['AID']=1121000177TextBox1.Text=1121000177
dr['apassword']= 123456TextBox2.Text=123456
用户名或密码不正确,请重新输入!
这是运行时页面打印出来的,其中第二个记录就是与数据库中数据完全一样,为什么还是现实用户名或密码不正确呢????
这是编码部分:
Session["AID"] = Server.HtmlEncode(TextBox1.Text.Trim());
SqlConnection sqlconn = new SqlConnection(connectstring);
string cmdText = "select AID,apassword from dbo.管理员";
SqlCommand command = new SqlCommand(cmdText, sqlconn);
try
{
//打开连接
sqlconn.Open();
//执行查询
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
Response.Write("dr['AID']=" + dr["AID"].ToString() + "TextBox1.Text=" + TextBox1.Text + "
");
Response.Write("dr['apassword']=" + dr["apassword"].ToString() + "TextBox2.Text=" + TextBox2.Text + "
");
if ((dr["AID"].ToString() == TextBox1.Text) && (dr["apassword"].ToString() == TextBox2.Text))
{
Response.Redirect("后台管理界面.aspx");
}

                  }
                 Response.Write("用户名或密码不正确,请重新输入!");
                dr.Close();
            }
            catch (SqlException sqlex)
            {
                //显示错误信息
                Response.Write(sqlex.Message + "<br>");
            }
            finally
            {
                //关闭数据连接
                sqlconn.Close();
            }
  • 写回答

1条回答 默认 最新

  • Tiger_Zhao 2015-08-31 06:11
    关注

    可能TextBox1.Text或TextBox2.Text有空格。

    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样