日期:2014-05-18  浏览次数:20676 次

新手求助!页面登录失败!
C# code

    protected void Page_Load(object sender, EventArgs e)
    { 
        if(!Page.IsPostBack)
        {
            sCap = Createcapstring(6); //验证码字符创建
            capimg.Src = sCapimageurl + sCap;
        }
    }
    protected void logbut_Click(object sender, EventArgs e)
    {
          if(Page.IsValid == true)
          {
              if(captxt.Text != sCap)
              {
                  string errortext = "验证码错误!";
                  capref.Text = errortext;
                  Response.Write("<script>alert('验证码错误!')</script>");
                  sCap = Createcapstring(6);
                  capimg.Src = sCapimageurl + sCap;
              }
              string adminid = "";                        
              //string adminname = Server.HtmlEncode(username.Text.Trim());
              //string adminpsd = Server.HtmlEncode(password.Text.Trim());
              string adminname = username.Text.Trim();
              string adminpsd = password.Text.Trim();
              string str = "SELECT * FROM T_Admin WHERE F_UserName='" + adminname + "' AND F_Password='" + password + "';";
              olecmd = new OleDbCommand(str, olecon);
              try
              {
                  olecon.Open();
                  OleDbDataReader oledr = olecmd.ExecuteReader(CommandBehavior.CloseConnection);
                  if (oledr.Read())
                  {
                      adminid = oledr["AdminID"].ToString();
                      Session["AdminID"] = adminid;
                      Response.Redirect("~/Crmain.aspx");       
                  }
                  else
                  {
                      Response.Write("<script>alert('用户名或密码有误!')</script>");
                  } 
                  oledr.Close();
                  oledr.Dispose();
              }
              catch (OleDbException oleex)
              {
                  throw oleex;
              }
              finally 
              {
                  olecon.Close();
              }  
          }
    }


C# code

   if (oledr.Read())
                  {
                      adminid = oledr["AdminID"].ToString();
                      Session["AdminID"] = adminid;
                      Response.Redirect("~/Crmain.aspx");       
                  }

加了断点,if (oledr.Read())没有执行直接跳进else,sql语句应该没问题啊,都没报错,试了很多总是登录错误,望各位大大帮忙看看

------解决方案--------------------
探讨

引用:

try
{
olecon.Open();
OleDbDataReader oledr = olecmd.ExecuteReader();
// OleDbDataReader oledr = olecmd.Execute……
取消了关闭部分,还是登陆不了